QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#612459 | #9449. New School Term | ucup-team5177# | WA | 1ms | 4004kb | C++14 | 3.5kb | 2024-10-05 11:22:17 | 2024-10-05 11:22:17 |
Judging History
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);
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 >= 1; -- 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;
}
for(int i = 2; i <= n+n; ++ i){
if(fa[i] != fa[px]){
mg(i, px);
}
if(fa[i] != fa[py]){
mg(i, py);
}
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(i, px);
}
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(i, py);
}
}
// for(int i = 1; i <= n+n; ++ i){
// // if(fa[i] == i){
// printf("%d %d %d %d %d\n", i, fa[i], col[i], 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: 4004kb
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: 3716kb
input:
3 7 2 5 1 3 4 6 2 6 4 5 2 4 5 6
output:
100101
result:
ok Output is valid. OK
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3760kb
input:
1 0
output:
00
result:
wrong answer The number of 0s must be equal to that of 1s.