QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#722636#9449. New School TermjimmyywangRE 2ms18028kbC++142.5kb2024-11-07 19:45:552024-11-07 19:45:57

Judging History

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

  • [2024-11-07 19:45:57]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:18028kb
  • [2024-11-07 19:45:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll int
#define f(i,a,b) for(ll i=a;i<=b;i++)
ll read(){
    ll x=0,f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    while(isdigit(c)){x=x*10+c-'0';c=getchar();}
    return x*f;
}
#define d read()
ll n,m;
ll fa[1000010],x[1000010],y[1000010];
ll find(ll x){if(fa[x]==x)return x;return find(fa[x]);}
ll U[1000010],V[1000010];
#define pb push_back
bitset<10010>dp;
bool ch(){
    ll s=0;dp.reset();dp[0]=1;
    f(i,1,2*n){ll t;
        if(find(i)==i)t=i;
        else if(find(i+2*n)==i+2*n)t=i+2*n;
        else continue;
        s+=min(x[t],y[t]);
        dp|=dp<<(abs(x[t]-y[t]));
    }return dp[n-s];
}
ll is[1000010];
bool in[1000010];
ll pre[1000010];
int main(){
    n=d,m=d;
    f(i,1,2*n)fa[i]=i,x[i]=1;
    f(i,2*n+1,4*n)fa[i]=i,y[i]=1;
    f(i,1,m)U[i]=d,V[i]=d;
    for(int i=m;i>=1;i--){
        ll u=U[i],v=V[i];
        if(find(u)==find(v)||find(u)==find(v+2*n))continue;
        // f(j,1,4*n)if(find(j)==j)cout<<x[j]<<" "<<y[j]<<"\n";cout<<endl;
        ll oux=x[find(u)],ouy=y[find(u)],ovx=x[find(v)],ovy=y[find(v)];
        ll ouux=x[find(u+2*n)],ouuy=y[find(u+2*n)],ovvx=x[find(v+2*n)],ovvy=y[find(v+2*n)];
        ll ou=fa[u],ov=fa[v],ouu=fa[u+2*n],ovv=fa[v+2*n];
        
        ll uu=find(u+2*n),vv=find(v+2*n);
        u=find(u),v=find(v);
        if(x[uu]+y[uu]>x[v]+y[v])swap(uu,v);
        fa[uu]=v,x[v]=x[uu]+x[v],y[v]=y[uu]+y[v];
        if(x[u]+y[u]>x[vv]+y[vv])swap(u,vv);
        fa[u]=vv,x[vv]=x[u]+x[vv],y[vv]=y[u]+y[vv];
        if(ch()){
            // e[U[i]].pb(V[i]);
            // e[V[i]].pb(U[i]);
            // cout<<U[i]<<" "<<V[i]<<endl;
            continue;
        }
        u=U[i],v=V[i];
        x[find(u)]=oux,y[find(u)]=ouy,x[find(v)]=ovx,y[find(v)]=ovy;
        x[find(u+2*n)]=ouux,y[find(u+2*n)]=ouuy,x[find(v+2*n)]=ovvx,y[find(v+2*n)]=ovvy;
        fa[u]=ou,fa[v]=ov,fa[u+2*n]=ouu,fa[v+2*n]=ovv;
    }
    ll s=0;in[0]=1;
    f(i,1,2*n){ll t;
        if(find(i)==i)t=i;
        else if(find(i+2*n)==i+2*n)t=i+2*n;
        else continue;
        s+=min(x[t],y[t]);ll q=abs(x[t]-y[t]);
        for(int j=n-q;j>=0;j--)if(!in[j+q]&&in[j]){
            in[j+q]=1;pre[j+q]=t;
        }if(x[t]<=y[t])is[t]=1;else is[t]=2;
    }s=n-s;
    while(1){
        ll p=pre[s];is[p]=3-is[p];
        s-=abs(x[p]-y[p]);
        if(s<=0)break;
    }f(i,1,2*n){
        if(is[find(i)]==1||is[find(i+2*n)]==2)cout<<0;
        else cout<<1;
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 17900kb

input:

2 4
1 3
2 4
1 4
1 2

output:

1010

result:

ok Output is valid. OK

Test #2:

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

input:

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

output:

110010

result:

ok Output is valid. OK

Test #3:

score: 0
Accepted
time: 1ms
memory: 11796kb

input:

1 0

output:

01

result:

ok Output is valid. OK

Test #4:

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

input:

1 1
1 2

output:

10

result:

ok Output is valid. OK

Test #5:

score: 0
Accepted
time: 2ms
memory: 15836kb

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

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: 2ms
memory: 15892kb

input:

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

output:

01010110

result:

ok Output is valid. OK

Test #8:

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

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:

0010111010

result:

ok Output is valid. OK

Test #9:

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

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: 2ms
memory: 15892kb

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:

111100011001101110000001

result:

ok Output is valid. OK

Test #11:

score: -100
Runtime Error

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:


result: