QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#612792 | #9449. New School Term | ucup-team5177# | RE | 0ms | 0kb | C++14 | 3.3kb | 2024-10-05 12:57:15 | 2024-10-05 12:57:16 |
answer
//O
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10, M = 2e6 + 10;
int n, m, a[M], b[M], col[N], fa[N];
int sx[N], sy[N];
typedef long long ll;
const int P = 998244853, Q = 1e9 + 9;
int f[5002], g[5002];
std::bitset<20009> vi[10009];
int bs = 0;
void del(int x, int r){
if(!x) return;
for(int i = x; i <= r; ++ i){
f[i] = (f[i] + P - f[i-x]) % P;
}
}
void ins(int x, int r){
if(!x) return;
for(int i = r; i >= x; -- i){
f[i] += f[i-x];
if(f[i] >= P) f[i] -= P;
// f[i] = (f[i] + f[i-x]) % P;
}
}
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];
int m=sx[xx]-sy[xx],n=sx[yy]-sy[yy];
if(m<0) {
m=-m;n=-n;
}
if(n<0) n=10000-n;
if(vi[m][n]) {
return;
}
memcpy(g, f, sizeof(g));
// memcpy(gg, ff, sizeof(gg));
int tt = bs;
if(sx[xx] == sy[xx] || sx[yy] == sy[yy]){
} else {
bs -= min(sx[xx], sy[xx]);
bs -= min(sx[yy], sy[yy]);
if(col[x] == col[y]){
bs += min(sx[xx]+sy[yy], sx[yy]+sy[xx]);
} else {
bs += min(sx[xx]+sx[yy], sy[xx]+sy[yy]);
}
del(abs(sx[xx] - sy[xx]), n-bs);
del(abs(sx[yy] - sy[yy]), n-bs);
if(col[x] == col[y]){
ins(abs(sx[xx]+sy[yy] - sx[yy]-sy[xx]), n-bs);
} else {
ins(abs(sx[xx]+sx[yy] - sy[xx]-sy[yy]), n-bs);
}}
if(f[n-bs]){
vi[m][n]=0;
memcpy(f, g, sizeof(g));
del(abs(sx[xx] - sy[xx]), n);
del(abs(sx[yy] - sy[yy]), n);
if(col[x] == col[y]){
ins(abs(sx[xx]+sy[yy] - sx[yy]-sy[xx]), n);
} else {
ins(abs(sx[xx]+sx[yy] - sy[xx]-sy[yy]), n);
}
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 {
vi[m][n]=1;
memcpy(f, g, sizeof(g));
bs = tt;
}
}
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]);
}
f[0] = 1;
for(int i = 1; i <= n + n; ++ i){
fa[i] = i;
sx[i] = 1;
ins(1, n);
}
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);
}
}
for(int i = 1; i <= n+n; ++ i){
putchar(col[i]+'0');
}
puts("");
return 0;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
2 4 1 3 2 4 1 4 1 2