QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#613489 | #9449. New School Term | ucup-team3161# | RE | 4ms | 15420kb | C++14 | 4.4kb | 2024-10-05 14:05:21 | 2024-10-05 14:09:07 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
//#define int long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
return f?-x:x;
}
#define mod 998244353
struct modint{
unsigned int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x<o.x?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,modint b){return a.x==b.x;}
friend bool operator !=(modint a,modint b){return a.x!=b.x;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f
int n,m,a[maxn],b[maxn];
int fa[maxn],s[maxn];
int gf(int x){
while(x!=fa[x])x=fa[x]=fa[fa[x]];
return x;
}
void mg(int u,int v){
u=gf(u),v=gf(v);
if(u!=v) {
fa[u]=v;
s[v]+=s[u];
s[u]=0;
}
}
int c[maxn];
bool f[maxn];
int ct[maxn],pre[maxn];
bool chk(){
int sum=0;
For(i,1,n)sum+=c[i]*i;
if(sum&1)return 0;
sum/=2;
For(i,1,sum)f[i]=0;
f[0]=1;
For(i,1,n)if(c[i]){
For(j,0,sum)ct[i]=0;
For(j,i,sum){
if(!f[j] && f[j-i] && ct[j-i]<c[i]){
f[j]=1;
ct[i]=ct[j-i]+1;
pre[j]=i;
}
}
}
return f[sum];
}
int nd[maxn];
int vis[maxn];
vi buc[maxn];
signed main()
{
n=read(),m=read();
For(i,1,m)a[i]=read(),b[i]=read();
For(i,1,n*4) {
fa[i]=i;
if(i<=n*2) s[i]=1; else s[i]=-1;
}
c[1]=n*2;
Rep(i,m,1){
if(gf(a[i])==gf(b[i]) || gf(a[i])==gf(b[i]+n*2)) continue;
int u=gf(a[i]),v=gf(b[i]+n*2);
int w1=abs(s[u]),w2=abs(s[v]),w3=abs(s[u]+s[v]);
--c[w1],--c[w2],++c[w3];
bool ok=chk();
if(ok){
// cout<<"dif "<<i<<"\n";
mg(a[i],b[i]+n*2);
mg(b[i],a[i]+n*2);
}else{
// cout<<"sam "<<i<<"\n";
++c[w2],--c[w3];
v=gf(b[i]);
w2=abs(s[v]),w3=abs(s[u]+s[v]);
--c[w2],++c[w3];
mg(a[i],b[i]);
mg(a[i]+n*2,b[i]+n*2);
}
}
int sum=0;
For(i,1,n)sum+=c[i]*i; sum/=2;
// cerr<<"sum "<<sum<<"\n";
chk();
assert(f[sum]);
int now=sum;
while(now) /*cout<<"pre "<<pre[now]<<"\n",*/nd[pre[now]]++,now-=pre[now];
For(i,1,n*4) vis[i]=-1,buc[gf(i)].pb(i);
For(ii,1,n*2) {
int i=gf(ii);
if(vis[(i<=n*2?i:i-n*2)]!=-1) continue;
int sz=abs(s[i]);
int s1=0,s0=0;
for(int x:buc[i]){
if((x<=n*2)) vis[x]=1,++s1;
else vis[x-n*2]=0,++s0;
}
if(s1>s0){
for(int x:buc[i]) {
if(x<=n*2) vis[x]^=1;
else vis[x-n*2]^=1;
}
}
if(nd[sz]){
// cout<<"flip "<<i<<"\n";
--nd[sz];
for(int x:buc[i]) {
if(x<=n*2) vis[x]^=1;
else vis[x-n*2]^=1;
}
}
}
For(i,1,n*2) cout<<vis[i];
return 0;
}
/*
3 1
1 2
3 2
5 6
4 6
6 3
1 2
2 3
3 4
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 15296kb
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: 3ms
memory: 15048kb
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: 15052kb
input:
1 0
output:
10
result:
ok Output is valid. OK
Test #4:
score: 0
Accepted
time: 0ms
memory: 13064kb
input:
1 1 1 2
output:
10
result:
ok Output is valid. OK
Test #5:
score: 0
Accepted
time: 0ms
memory: 15420kb
input:
2 3 2 4 3 4 1 2
output:
1001
result:
ok Output is valid. OK
Test #6:
score: 0
Accepted
time: 3ms
memory: 14100kb
input:
3 8 4 6 3 5 1 4 2 4 1 6 1 2 3 4 4 5
output:
101010
result:
ok Output is valid. OK
Test #7:
score: 0
Accepted
time: 4ms
memory: 15416kb
input:
4 9 4 7 3 8 1 5 2 7 2 8 6 8 7 8 1 4 1 6
output:
10101001
result:
ok Output is valid. OK
Test #8:
score: 0
Accepted
time: 0ms
memory: 13504kb
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:
1101000101
result:
ok Output is valid. OK
Test #9:
score: 0
Accepted
time: 0ms
memory: 13788kb
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:
001001110110
result:
ok Output is valid. OK
Test #10:
score: 0
Accepted
time: 3ms
memory: 14036kb
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...