QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#612352#9449. New School Termucup-team5177#WA 1ms3844kbC++142.3kb2024-10-05 10:39:242024-10-05 10:39:25

Judging History

你现在查看的是最新测评结果

  • [2024-10-05 10:39:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3844kb
  • [2024-10-05 10:39:24]
  • 提交

answer

//O
#include <bits/stdc++.h>
using namespace std;

const int N = 1e4 + 10;
int n, m, a[N], b[N], col[N], fa[N];
int sx[N], sy[N];
typedef long long ll;
const ll P = 998244853;
ll f[N], g[N];

int bs = 0;
void del(int x){
    if(!x) return;
    // printf("del %d\n", x);
    for(int i = x; i <= n+n; ++ i){
        f[i] = (f[i] + P - f[i-x]) % P;
    }
}
void ins(int x){
    if(!x) return;
    // printf("ins %d\n", x);
    for(int i = n+n; i >= x; -- i){
        f[i] = (f[i] + f[i-x]) % P;
    }
}
bool chk(){
    // int x;
    // printf("chk:%d\n", bs);
    // scanf("%d", &x);
    // printf("%d\n", f[n-bs]);
    return f[n-bs];
}

int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; ++ i){
        scanf("%d%d", &a[i], &b[i]);
        // a[i] = i;
        // b[i] = i+n;
    }
    f[0] = 1;
    for(int i = 1; i <= n + n; ++ i){
        fa[i] = i;
        sx[i] = 1;
        ins(1);
    }
    for(int i = m; i >= 1; -- i){
        int x = a[i], y = b[i];
        if(fa[x] == fa[y]){
            continue;
        }
        int xx = fa[x];
        int yy = fa[y];
        memcpy(g, f, sizeof(g));
        del(abs(sx[xx] - sy[xx]));
        bs -= min(sx[xx], sy[xx]);
        del(abs(sx[yy] - sy[yy]));
        bs -= min(sx[yy], sy[yy]);
        if(col[x] == col[y]){
            ins(abs(sx[xx]+sy[yy] - sx[yy]-sy[xx]));
            bs += min(sx[xx]+sy[yy], sx[yy]+sy[xx]);
        } else {
            ins(abs(sx[xx]+sx[yy] - sy[xx]-sy[yy]));
            bs += min(sx[xx]+sx[yy], sy[xx]+sy[yy]);
        }
        if(chk()){
            if(col[x] == col[y]){
                sx[xx] += sy[yy];
                sy[xx] += sx[yy];
            } else {
                sx[xx] += sx[yy];
                sy[xx] += sy[yy];
            }
            sx[yy] = sy[yy] = 0;
            for(int j = 1; j <= n+n; ++ j){
                if(fa[j] == yy){
                    fa[j] = xx;
                    if(col[x] == col[y]){
                        col[j] ^= 1;
                    }
                }
            }
        } else {
            memcpy(f, g, sizeof(g));
        }
        // for(int i = 1; i <= n + n; ++ i){
        //     printf("%d %d %d %d\n", fa[i], col[i], sx[i], sy[i]);
        // }
    }
    for(int i = 1; i <= n+n; ++ i){
        putchar(col[i]+'0');
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3788kb

input:

2 4
1 3
2 4
1 4
1 2

output:

0101

result:

ok Output is valid. OK

Test #2:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

3 7
2 5
1 3
4 6
2 6
4 5
2 4
5 6

output:

001101

result:

ok Output is valid. OK

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3836kb

input:

1 0

output:

00

result:

wrong answer The number of 0s must be equal to that of 1s.