QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#643203#9449. New School Termicpc_zhzx034WA 3ms11864kbC++143.6kb2024-10-15 19:47:322024-10-15 19:47:33

Judging History

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

  • [2024-10-15 19:47:33]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:11864kb
  • [2024-10-15 19:47:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pr;
#define fi first
#define se second
#define mkp make_pair
#define pb emplace_back
// #define mid ((l+r)>>1)
#define popcnt __builtin_popcountll
inline ll read(){
	ll x=0, f=1; char ch=getchar();
	while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
	while(ch>='0' && ch<='9') x=x*10+ch-'0', ch=getchar();
	return x*f;
}
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
void init(){ }
const ll mod = 979532918953082881ll;
const ll N = 20000;
ll n,m,a[1000005],b[1000005];

ll fa[20005], sz[20005];
ll f[20005];
ll find(ll x){
	if(x!=fa[x]) fa[x]=find(fa[x]);
	return fa[x];
}
void addmod(ll &x){ (x >= mod) && (x -= mod); }

ll base;
void add(int u,int v){
	// cout<<"add "<<u<<" "<<v<<endl;
	if(u>v) swap(u, v); v-=u;
	base += u;
	for(int i=N;i>=v;i--) addmod(f[i]+=f[i-v]);
}
void del(int u,int v){
	// cout<<"del "<<u<<" "<<v<<endl;
	if(u>v) swap(u, v); v-=u;
	base -= u;
	if(v){
		for(int i=v;i<=N;i++){
			addmod(f[i]+=mod-f[i-v]);
		}
	}else{
		for(int i=v;i<=N;i++){
			if(f[i]&1) f[i]=((f[i]+mod)>>1);
			else f[i]>>=1;
		}
	}
}
void merge(ll x,ll y){
	x=find(x), y=find(y);
	if(x==y) return;
	if(x<y) swap(x, y);
	fa[x] = y; sz[y] += sz[x];
}

int up[20005], down[20005], seq[20005], tl;
vector<int>vec[20005][2];

bitset<20005>dp[20005],jc[20005];
void print(){
	for(ll i=0;i<=n;i++){
		printf("%lld ", f[i]);
	}
	puts("");
}
bool ans[20005];

bool visq[20005];
void procedure(){
	n=read()*2,m=read();
	for(ll i=1;i<=m;i++){
		a[i]=read(), b[i]=read();
	}
	for(ll i=1;i<=2*n;i++) sz[i]=(i<=n), fa[i]=i;
	f[0] = 1;
	for(ll i=1;i<=n;i++) add(0, 1);

	// print();
	// cout<<"firstly"<<endl;
	for(ll i=m;i>=1;i--){
		if(find(a[i]) == find(b[i]) || find(a[i]) == find(b[i]+n)) continue;
		ll u1 = sz[find(a[i])], v1 = sz[find(a[i]+n)];
		ll u2 = sz[find(b[i]+n)], v2 = sz[find(b[i])];
		del(u1, u2); del(u2, v2);
		add(u1+u2, v1+v2);
		// print();
		if(n/2 >= base && f[n/2-base]){

			// cout<<"not same "<<a[i]<<" "<<b[i]<<endl;
			merge(a[i], b[i]+n);
			merge(a[i]+n, b[i]);
		}else{
			del(u1+u2, v1+v2); 
			add(u1+v2, v1+u2);

			// cout<<"same "<<a[i]<<" "<<b[i]<<endl;
			merge(a[i], b[i]);
			merge(a[i]+n, b[i]+n);
		}
		// cout<<"time = "<<i<<endl;
	}

	// cout<<"solved"<<endl;

	// for(ll i=1;i<=n;i++) printf("%lld ", find(i)); puts("");
	// for(ll i=1;i<=n;i++) printf("%lld ", find(i+n)); puts("");

	for(ll i=1;i<=2*n;i++){
		if(i <= n) up[find(i)]++, vec[find(i)][0].pb(i);
		else down[find(i)]++, vec[find(i)][1].pb(i-n);
	}

	for(ll i=1;i<=n;i++){
		if(!vec[i][0].size() || visq[i]) continue;
		seq[++tl] = i;
		visq[find(i+n)] = 1;
	}

	// for(ll i=1;i<=tl;i++){
	// 	cout<<seq[i]<<" "<<up[seq[i]]<<" "<<down[seq[i]]<<endl;
	// }

	dp[0][0] = 1;
	for(ll i=1;i<=tl;i++){
		for(ll j=0;j<=n/2;j++){
			if(j >= up[seq[i]]){
				if(dp[i-1][j-up[seq[i]]]){
					jc[i][j] = 0;
					dp[i][j] = 1;
				}
			}
			if(j >= down[seq[i]]){
				if(dp[i-1][j-down[seq[i]]]){
					jc[i][j] = 1;
					dp[i][j] = 1;
				}
			}
		}
	}

	for(ll i=tl, j=n/2; i>=1; i--){
		// cout<<"jc is "<<(bool)(jc[i][j])<<endl;
		if(jc[i][j]){
			for(auto x: vec[seq[i]][1]) ans[x] = 1;
			j -= down[seq[i]];
		}else{
			for(auto x: vec[seq[i]][0]) ans[x] = 1;
			j -= up[seq[i]];
		}
	}

	for(ll i=1;i<=n;i++) putchar(ans[i]+'0');
	puts("");
}
int main(){
	#ifdef LOCAL
		assert(freopen("input.txt","r",stdin));
		assert(freopen("output.txt","w",stdout));
	#endif
	ll T=1;
	init();
	while(T--) procedure();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 11848kb

input:

2 4
1 3
2 4
1 4
1 2

output:

0101

result:

ok Output is valid. OK

Test #2:

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

input:

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

output:

001101

result:

ok Output is valid. OK

Test #3:

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

input:

1 0

output:

10

result:

ok Output is valid. OK

Test #4:

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

input:

1 1
1 2

output:

01

result:

ok Output is valid. OK

Test #5:

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

input:

2 3
2 4
3 4
1 2

output:

0110

result:

ok Output is valid. OK

Test #6:

score: -100
Wrong Answer
time: 2ms
memory: 9724kb

input:

3 8
4 6
3 5
1 4
2 4
1 6
1 2
3 4
4 5

output:

100100

result:

wrong answer The number of 0s must be equal to that of 1s.