QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#612789#9449. New School Termucup-team5177#RE 0ms0kbC++143.3kb2024-10-05 12:56:342024-10-05 12:56:34

Judging History

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

  • [2024-10-05 12:56:34]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-05 12:56:34]
  • 提交

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;
	} 
	n+=2*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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

2 4
1 3
2 4
1 4
1 2

output:


result: