2018 JUST Programming Contest 1.0 H. Genta Game

水题一道,不过我为什么要将她记录下来呢,在wa了无数次后,我胡乱的吧输入同步(#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);)取消掉了,结果就ac了,看来以后还是打scanfprintf好,不能再偷懒了。

#include 
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define ll long long
#define ld long double
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG cout< pii;
const int maxn = 3e5 + 200;
int n, m, y[1000010];
char c, s[1000010];
int main() {
    int t;
    cin >> t;
    while(t--) {
        me(y);
        int ans = 0, bu = 0, k = 0;
        scanf("%d %d", &n, &m);
        scanf("%s", s);
        k = n;
        if(n & 1)
            k = n, y[n / 2] = 0, n--;
        for(int i = 0; i < n / 2; i++) {
            if(s[i] != s[k - 1 - i]) {
                y[i] = y[k - 1 - i] = 1, bu++;
            } else
                y[i] = y[k - 1 - i] = 0;
        }
        for(int i = 1, x; i <= m; i++) {
            char ch[2];
            scanf("%d %s", &x, ch);
            s[--x] = ch[0];
            if((k & 1) && x == k / 2) {
                if(!bu) {
                    ans++;
                }
                continue;
            }
            if(y[x] == 1 && s[x] == s[k - 1 - x]) {
                y[x] = y[k - 1 - x] = 0;
                bu--;
            } else if(s[x] != s[k - 1 - x] && y[x] == 0) {
                y[x] = y[k - 1 - x] = 1;
                bu++;
            }
            if(!bu) {
                ans++;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

 

你可能感兴趣的:(codeforces)