QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#616127 | #9449. New School Term | ucup-team3586# | WA | 1ms | 5796kb | C++23 | 2.9kb | 2024-10-05 22:36:22 | 2024-10-05 22:36:23 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
const int mod=1e9+9;
void add(int &a,int b)
{
a+=b;
if(a>=mod) a-=mod;
}
void sub(int &a,int b)
{
a-=b;
if(a<0) a+=mod;
}
int n,m;
int a[1001000],b[1001000];
int siz[10005][2];
int fa[10005],d[10005];
int anc(int x)
{
if(fa[x]==x) return x;
int y=anc(fa[x]);
d[x]^=d[fa[x]];
fa[x]=y;
return y;
}
int f[5005],g[5005];
map<pii,int> Mp;
int color[10005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=m;i++)
cin>>a[i]>>b[i];
for(int i=1;i<=n+n;i++)
{
fa[i]=i;
siz[i][0]=1;
}
f[0]=1;
for(int i=1;i<=n+n;i++)
for(int j=n;j>=0;j--)
add(f[j+1],f[j]);
int tot=0;
for(int i=m;i>=1;i--)
{
int u=a[i],v=b[i];
if(anc(u)==anc(v))
continue;
int x=siz[anc(u)][0]-siz[anc(u)][1];
int y=siz[anc(v)][0]-siz[anc(v)][1];
if(d[u]==d[v])
y=-y;
if(x<0)
{
x=-x;
y=-y;
}
if(Mp[mp(x,y)]) continue;
memcpy(g,f,sizeof(f));
if(abs(x))
for(int j=abs(x);j<=n;j++)
sub(f[j],f[j-abs(x)]);
if(abs(y))
for(int j=abs(y);j<=n;j++)
sub(f[j],f[j-abs(y)]);
if(abs(x+y))
for(int j=n-abs(x+y);j>=0;j--)
add(f[j+abs(x+y)],f[j]);
if(abs(x+y)!=abs(x)+abs(y))
tot+=min(abs(x),abs(y));
if(f[n-tot])
{
if(d[u]!=d[v])
{
siz[anc(u)][0]+=siz[anc(v)][0];
siz[anc(u)][1]+=siz[anc(v)][1];
}
else
{
siz[anc(u)][0]+=siz[anc(v)][1];
siz[anc(u)][1]+=siz[anc(v)][0];
}
d[anc(v)]=d[u]^d[v]^1;
fa[anc(v)]=anc(u);
}
else
{
memcpy(f,g,sizeof(f));
if(abs(x+y)!=abs(x)+abs(y))
tot-=min(abs(x),abs(y));
Mp[mp(x,y)]=1;
}
}
int cur=n-tot;
for(int i=1;i<=n+n;i++)
if(fa[i]==i)
{
int val=abs(siz[i][0]-siz[i][1]);
if(!val)
{
for(int j=1;j<=n+n;j++)
if(anc(j)==i)
if(!d[j])
color[j]=1;
continue;
}
if(val)
for(int j=val;j<=n;j++)
sub(f[j],f[j-val]);
int flag=f[cur]>0;
if(!f[cur]) cur-=val;
if(siz[i][0]>siz[i][1]) flag^=1;
if(flag)
{
for(int j=1;j<=n+n;j++)
if(anc(j)==i)
if(!d[j])
color[j]=1;
}
else
{
for(int j=1;j<=n+n;j++)
if(anc(j)==i)
if(d[j])
color[j]=1;
}
}
for(int i=1;i<=n+n;i++)
cout<<color[i];
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5692kb
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: 5672kb
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: 0ms
memory: 3592kb
input:
1 0
output:
01
result:
ok Output is valid. OK
Test #4:
score: 0
Accepted
time: 1ms
memory: 5796kb
input:
1 1 1 2
output:
10
result:
ok Output is valid. OK
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 5736kb
input:
2 3 2 4 3 4 1 2
output:
1000
result:
wrong answer The number of 0s must be equal to that of 1s.