QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613795#9449. New School Termucup-team3161#WA 10ms14108kbC++144.8kb2024-10-05 14:45:532024-10-05 14:45:55

Judging History

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

  • [2024-10-05 14:45:55]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:14108kb
  • [2024-10-05 14:45:53]
  • 提交

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[20005];
int ct[20005],pre[20005];
int szf=0;

bool chk(){
	int sum=0;
	For(i,1,n*2)sum+=c[i]*i;
	sum=szf;
	if(sum&1) assert(0);
	sum/=2;
	memset(f,0,sizeof f);
	f[0]=1;
	For(i,1,sum)if(c[i]){
		memset(ct,0,sizeof ct);
		For(j,i,sum){
			if(!f[j] && f[j-i] && ct[j-i]<c[i]){
				f[j]=1;
				ct[j]=ct[j-i]+1;
				pre[j]=i;
			}
		}
	}
	return f[sum];
}
int nd[maxn];

int vis[maxn];
vi  buc[maxn];

int ck[maxn];

signed main()
{
//	freopen("data.in","r",stdin);
//	freopen("my.out","w",stdout);
	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;
	szf=n*2;
	Rep(i,m,1){
		ck[i]=-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];
		szf+=w3-w2-w1;
		bool ok=chk();
		if(ok){
	//		cout<<"dif "<<i<<"\n";
			mg(a[i],b[i]+n*2);
			mg(b[i],a[i]+n*2);
			ck[i]=1;
		}else{
	//		cout<<"sam "<<i<<"\n";
			++c[w2],--c[w3]; szf+=w2-w3;
			
			v=gf(b[i]);
			w2=abs(s[v]),w3=abs(s[u]+s[v]);
			--c[w2],++c[w3]; szf+=w3-w2;
			
			mg(a[i],b[i]);
			mg(a[i]+n*2,b[i]+n*2);
			ck[i]=0;
		}
	}
	
	int sum=0;
	For(i,1,n*2)sum+=c[i]*i; sum/=2;
	cerr<<"sum "<<sum<<"\n";
	chk();
	assert(f[sum]);
//	exit(0);
	
	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];
	int ss=0;
	For(i,1,n*2) assert(vis[i]!=-1),ss+=(vis[i]!=0);
	assert(ss==n);
	Rep(i,m,1){
		if(ck[i]!=-1){
			if(ck[i]==1) assert(vis[a[i]]!=vis[b[i]]);
			else assert(vis[a[i]]==vis[b[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: 3ms
memory: 13864kb

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

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

input:

1 0

output:

10

result:

ok Output is valid. OK

Test #4:

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

input:

1 1
1 2

output:

10

result:

ok Output is valid. OK

Test #5:

score: 0
Accepted
time: 3ms
memory: 13856kb

input:

2 3
2 4
3 4
1 2

output:

1001

result:

ok Output is valid. OK

Test #6:

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

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: 3ms
memory: 13004kb

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: 3ms
memory: 13800kb

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

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

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: 0
Accepted
time: 3ms
memory: 13340kb

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:

111000110010111001101110000111000000011111100010101100100010001110101101111110000111000101111100010110101110111100011010101100111010010011101010011010011010011101100111001011110001100111000010101011100110110001001010010010101010010110011001100001010110000100001110101110000010110001010010000110110011...

result:

ok Output is valid. OK

Test #12:

score: -100
Wrong Answer
time: 10ms
memory: 14108kb

input:

811 265557
217 1153
383 1609
165 177
612 1602
1057 1428
37 436
135 1200
368 684
448 722
145 1583
325 1052
246 480
74 148
122 1111
1256 1327
304 1070
1285 1542
802 813
454 1563
265 1193
94 848
432 1156
429 1194
427 1230
1152 1406
1329 1355
702 845
591 1232
877 1288
1257 1549
340 659
1080 1333
910 137...

output:

110101111111011011111110111111101111011001101111111101111111111011111111111111111100111011101011110111111111111111010011101110110111110111101111111011111111011111111101011110110001011011111100011111011111111111101011111001101111111111111011011111110111110011111111111001010101111111111110111111111110...

result:

wrong answer The division is not minimized.