QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#612472#9449. New School Termucup-team5177#WA 7ms4212kbC++143.5kb2024-10-05 11:27:282024-10-05 11:27:28

Judging History

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

  • [2024-10-05 11:27:28]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:4212kb
  • [2024-10-05 11:27:28]
  • 提交

answer

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

const int N = 1e4 + 10;
int n, m, a[N*3], b[N*3], 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){
    // printf("del %d\n", x);
    if(!x) return;
    for(int i = x; i <= n+n; ++ i){
        f[i] = (f[i] + P - f[i-x]) % P;
    }
}
void ins(int x){
    // printf("ins %d\n", x);
    if(!x) return;
    for(int i = n+n; i >= x; -- i){
        f[i] = (f[i] + f[i-x]) % P;
    }
}
bool chk(){
    // printf("chk %d %d\n", bs, f[n-bs]);
    return f[n-bs];
}

void mg(int pp, int qq){
    // printf("%d %d\n", pp, qq);
    int x = pp, y = qq;
    if(fa[x] == fa[y]){
        return;
    }
    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()){
        // puts("ok");
        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;
        bool op = (col[x] == col[y]);
        for(int j = 1; j <= n+n; ++ j){
            if(fa[j] == yy){
                fa[j] = xx;
                if(op){
                    col[j] ^= 1;
                }
            }
        }
    } else {
        memcpy(f, g, sizeof(g));
    }
}

int main(){
    // srand(time(0));
    scanf("%d%d", &n, &m);
    a[0] = 1, b[0] = 2;
    for(int i = 1; i <= m; ++ i){
        scanf("%d%d", &a[i], &b[i]);
        // a[i] = 1;
        // b[i] = n+n-i+1;
        // a[i] = rand() % (n+n) + 1;
        // b[i] = rand() % (n+n) + 1;
        // printf("%d %d\n", a[i], b[i]);
    }
    f[0] = 1;
    for(int i = 1; i <= n + n; ++ i){
        fa[i] = i;
        sx[i] = 1;
        ins(1);
    }
    for(int i = m; i >= 0; -- i){
        mg(a[i], b[i]);
    }
    int px = 0, py = 0, cl = 0;
    for(int i = 1; i <= n+n; ++ i){
        if(sx[i] && sy[i]){
            cl = i;
            break;
        }
    }
    for(int i = 1; i <= n+n; ++ i){
        if(fa[i] == cl && col[i] == 0) px = i;
        if(fa[i] == cl && col[i] == 1) py = i;
    }
    // printf("%d %d\n", px, py);
    for(int i = 2; i <= n+n; ++ i){
        if(fa[i] != fa[px]){
            mg(px, i);
        }
        if(fa[i] != fa[py]){
            mg(py, i);
        }
        if(fa[i] != fa[px]){
            // puts("123");
            for(int j = 1; j <= n+n; ++ j){
                if(fa[j] == fa[i]){
                    col[j] ^= 1;
                }
            }
            swap(sx[fa[i]], sy[fa[i]]);
            mg(px, i);
        }
        if(fa[i] != fa[py]){
            // puts("123");
            for(int j = 1; j <= n+n; ++ j){
                if(fa[j] == fa[i]){
                    col[j] ^= 1;
                }
            }
            swap(sx[fa[i]], sy[fa[i]]);
            mg(py, i);
        }
    }
    // for(int i = 1; i <= n+n; ++ i){
    //     if(fa[i] == i){
    //         printf("%d %d\n", sx[i], sy[i]);
    //     }
    // }
    for(int i = 1; i <= n+n; ++ i){
        putchar(col[i]+'0');
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3792kb

input:

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

output:

011010

result:

ok Output is valid. OK

Test #3:

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

input:

1 0

output:

01

result:

ok Output is valid. OK

Test #4:

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

input:

1 1
1 2

output:

01

result:

ok Output is valid. OK

Test #5:

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

input:

2 3
2 4
3 4
1 2

output:

0110

result:

ok Output is valid. OK

Test #6:

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

input:

3 8
4 6
3 5
1 4
2 4
1 6
1 2
3 4
4 5

output:

010101

result:

ok Output is valid. OK

Test #7:

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

input:

4 9
4 7
3 8
1 5
2 7
2 8
6 8
7 8
1 4
1 6

output:

10101001

result:

ok Output is valid. OK

Test #8:

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

input:

5 16
3 6
9 10
2 7
1 10
1 5
2 10
3 5
5 6
3 4
2 5
4 5
3 8
4 7
6 8
1 6
7 10

output:

1101000101

result:

ok Output is valid. OK

Test #9:

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

input:

6 13
4 5
2 9
3 8
4 8
4 11
10 12
3 4
3 9
5 11
2 8
5 10
5 8
1 11

output:

110110001001

result:

ok Output is valid. OK

Test #10:

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

input:

12 153
1 24
16 18
7 14
1 16
20 21
9 14
21 22
4 5
17 24
4 12
5 17
13 24
14 15
12 23
12 16
8 11
14 24
9 16
2 5
6 19
11 17
4 22
4 7
6 16
7 20
8 15
5 24
2 10
10 21
21 24
1 12
11 19
18 21
18 24
12 17
13 22
7 9
13 23
4 9
11 13
15 21
5 7
2 4
15 16
17 19
11 16
11 20
7 8
4 15
13 14
6 18
2 19
9 13
23 24
4 21
...

output:

000011100110010001111110

result:

ok Output is valid. OK

Test #11:

score: -100
Wrong Answer
time: 7ms
memory: 4212kb

input:

259 33757
472 500
65 336
138 469
307 442
427 458
43 239
17 508
460 466
108 393
79 92
250 483
44 277
17 132
35 57
155 499
184 474
246 272
274 418
457 458
338 372
196 514
31 208
117 187
90 229
153 284
189 355
16 337
146 456
269 271
279 412
305 336
303 441
399 472
85 286
91 97
157 437
137 379
71 360
27...

output:

011111111111111111111111111111111111111111111111111111110111111111111111111111111111111111101111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111011111111111111111111011111111111111111111011111111101111111111111111111100000000010000100001000000000000000000000...

result:

wrong answer The division is not minimized.