• 欢迎光临~

Codeforces Round #785 (Div. 2) A-C

Problem A

```#include <bits/stdc++.h>
using namespace std;
constexpr int limit =  (400000 + 5);//防止溢出
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步两步
#define EPS 1e-9
#define FASTIO  ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
#define ff(a) printf("%dn",a );
#define pi(a, b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a  ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].nxt)
#define FOPEN freopen("C:\Users\tiany\CLionProjects\akioi\data.txt", "rt", stdin)
#define FOUT freopen("C:\Users\tiany\CLionProjects\akioi\dabiao.txt", "wt", stdout)
typedef long long ll;
typedef unsigned long long ull;
char buf[1 << 23], *p1 = buf, *p2 = buf, obuf[1 << 23], *O = obuf;

inline ll read() {
ll sign = 1, x = 0;
char s = getchar();
while (s > '9' || s < '0') {
if (s == '-')sign = -1;
s = getchar();
}
while (s >= '0' && s <= '9') {
x = (x << 3) + (x << 1) + s - '0';
s = getchar();
}
return x * sign;
#undef getchar
}//快读
void print(ll x) {
if (x / 10) print(x / 10);
*O++ = x % 10 + '0';
}

void write(ll x, char c = 't') {
if (x < 0)putchar('-'), x = -x;
print(x);
if (!isalpha(c))*O++ = c;
fwrite(obuf, O - obuf, 1, stdout);
O = obuf;
}

int n,m;
int a[limit];
int sum[limit];
void solve(){
string str;
cin>>str;
n = str.size();
str = " " + str;
rep(i,1,n){
a[i] = str[i] - 'a' + 1;
sum[i] = sum[i - 1] + a[i];
//        cout<<a[i]<<" ";
}
if(n == 1){
cout<<"Bob"<<" "<<str[1] - 'a' + 1<<endl;
return;
}else if(n & 1){
int maxx = max(sum[n] - sum[1], sum[n - 1]);
cout<<"Alice"<<" "<<abs((sum[n] - maxx) - maxx)<<endl;
}else{
cout<<"Alice"<<" "<<sum[n]<<endl;
}

};
int32_t main() {
#ifdef LOCAL
FOPEN;
//    FOUT;
#endif
FASTIO
int kase;
cin>>kase;
while (kase--)
solve();
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "sn";
return 0;
}```
AC Code

Problem B

```#include <bits/stdc++.h>
using namespace std;
constexpr int limit =  (400000 + 5);//防止溢出
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步两步
#define EPS 1e-9
#define FASTIO  ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
#define ff(a) printf("%dn",a );
#define pi(a, b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a  ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].nxt)
#define FOPEN freopen("C:\Users\tiany\CLionProjects\akioi\data.txt", "rt", stdin)
#define FOUT freopen("C:\Users\tiany\CLionProjects\akioi\dabiao.txt", "wt", stdout)
typedef long long ll;
typedef unsigned long long ull;
char buf[1 << 23], *p1 = buf, *p2 = buf, obuf[1 << 23], *O = obuf;

inline ll read() {
ll sign = 1, x = 0;
char s = getchar();
while (s > '9' || s < '0') {
if (s == '-')sign = -1;
s = getchar();
}
while (s >= '0' && s <= '9') {
x = (x << 3) + (x << 1) + s - '0';
s = getchar();
}
return x * sign;
#undef getchar
}//快读
void print(ll x) {
if (x / 10) print(x / 10);
*O++ = x % 10 + '0';
}

void write(ll x, char c = 't') {
if (x < 0)putchar('-'), x = -x;
print(x);
if (!isalpha(c))*O++ = c;
fwrite(obuf, O - obuf, 1, stdout);
O = obuf;
}

int n,m;
int a[limit];
int sum[limit][30];
vector<int>g[limit];
void solve(){
string str;
cin>>str;
n = str.size();

auto s = set<char>{str.begin(), str.end()};
str = " " + str;
rep(i,0,26)g[i].clear();
rep(i,1,n){

rep(j,0,25){

sum[i][j] = sum[i - 1][j] + (str[i] - 'a' == j);
}
}

map<char, int>mp;
rep(i,1,n){
mp[str[i]]++;
g[str[i] - 'a'].push_back(i);
}
rep(i,0,25){

if(g[i].size() <= 1)continue;
rep(j, 1, g[i].size() - 1){
int l = g[i][j - 1];
int r = g[i][j];
set<char>st;
rep(h,l + 1, r){
st.insert(str[h]);
}
if(st.size() != mp.size()){
//                cout<<str<<" "<<l<<" "<<r<<endl;
cout<<"No"<<endl;
return;
}

}
}
cout<<"Yes"<<endl;

};
int32_t main() {
#ifdef LOCAL
FOPEN;
//    FOUT;
#endif
FASTIO
int kase;
cin>>kase;
while (kase--)
solve();
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "sn";
return 0;
}```
AC Code

Problem C

```#include <bits/stdc++.h>
using namespace std;
constexpr int limit =  (400000 + 5);//防止溢出
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步两步
#define EPS 1e-9
#define FASTIO  ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
#define ff(a) printf("%dn",a );
#define pi(a, b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a  ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].nxt)
#define FOPEN freopen("C:\Users\tiany\CLionProjects\akioi\data.txt", "rt", stdin)
#define FOUT freopen("C:\Users\tiany\CLionProjects\akioi\dabiao.txt", "wt", stdout)
typedef long long ll;
typedef unsigned long long ull;
char buf[1 << 23], *p1 = buf, *p2 = buf, obuf[1 << 23], *O = obuf;

inline ll read() {
ll sign = 1, x = 0;
char s = getchar();
while (s > '9' || s < '0') {
if (s == '-')sign = -1;
s = getchar();
}
while (s >= '0' && s <= '9') {
x = (x << 3) + (x << 1) + s - '0';
s = getchar();
}
return x * sign;
#undef getchar
}//快读
void print(ll x) {
if (x / 10) print(x / 10);
*O++ = x % 10 + '0';
}

void write(ll x, char c = 't') {
if (x < 0)putchar('-'), x = -x;
print(x);
if (!isalpha(c))*O++ = c;
fwrite(obuf, O - obuf, 1, stdout);
O = obuf;
}

int n,m;
int a[limit];
bool isPalindrome(int x){
int tmp = x;
int sum = 0;
while(tmp){
sum = sum * 10 + tmp % 10;
tmp /= 10;
}
return sum == x;
}
int tot;
ll dp[40005][501];
const ll mod = 1e9 + 7;
void init(){
n = 4e4;
tot = 0;
rep(i,1,n){
if(isPalindrome(i)){
a[++tot] = i;
}
}
rep(i,1,tot){
dp[0][i] = 1;
}
rep(i,1,n){
rep(j,1,tot){
if(i - a[j] >= 0){
dp[i][j] = (dp[i][j - 1] + dp[i - a[j]][j]) % mod;
}else{
dp[i][j] = dp[i][j - 1] % mod;
}
}
}
}

void solve(){
cin>>n;

cout<<(1ll * dp[n][tot]) % mod<<endl;
};
int32_t main() {
#ifdef LOCAL
FOPEN;
//    FOUT;
#endif
FASTIO
init();
int kase;
cin>>kase;
while (kase--)
solve();
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "sn";
return 0;
}```
AC Code

D有点头绪，但是因为前两题莫名wa2所以没时间做了，回去研究下