QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#612392 | #9449. New School Term | ucup-team5177# | WA | 1ms | 4004kb | C++14 | 2.2kb | 2024-10-05 10:50:21 | 2024-10-05 10:50:21 |
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){
if(!x) return;
for(int i = x; i <= n+n; ++ i){
f[i] = (f[i] + P - f[i-x]) % P;
}
}
void ins(int x){
if(!x) return;
for(int i = n+n; i >= x; -- i){
f[i] = (f[i] + f[i-x]) % P;
}
}
bool chk(){
return f[n-bs];
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 1; i < n+n; ++ i){
a[i] = 1;
b[i] = i+1;
}
for(int i = n+n; i < n+n+m; ++ i){
scanf("%d%d", &a[i], &b[i]);
// a[i] = 1;
// b[i] = n+n-i+1;
}
f[0] = 1;
for(int i = 1; i <= n + n; ++ i){
fa[i] = i;
sx[i] = 1;
ins(1);
}
for(int i = n+n+m-1; 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){
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: 3808kb
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: 3732kb
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: 0
Accepted
time: 0ms
memory: 3928kb
input:
1 0
output:
01
result:
ok Output is valid. OK
Test #4:
score: 0
Accepted
time: 1ms
memory: 3728kb
input:
1 1 1 2
output:
01
result:
ok Output is valid. OK
Test #5:
score: 0
Accepted
time: 1ms
memory: 3864kb
input:
2 3 2 4 3 4 1 2
output:
0110
result:
ok Output is valid. OK
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 4004kb
input:
3 8 4 6 3 5 1 4 2 4 1 6 1 2 3 4 4 5
output:
010111
result:
wrong answer The number of 0s must be equal to that of 1s.