QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#299364#7863. Parity Gameucup-team134#RE 1ms3804kbC++176.6kb2024-01-06 19:46:272024-01-06 19:46:28

Judging History

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

  • [2024-01-06 19:46:28]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3804kb
  • [2024-01-06 19:46:27]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<int D, typename T>struct vec : public vector<vec<D - 1, T>> {template<typename... Args>vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {}};
template<typename T>struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val) {}};
template<class T1,class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int ri(){int x;scanf("%i",&x);return x;}
void rd(int&x){scanf("%i",&x);}
void rd(long long&x){scanf("%lld",&x);}
void rd(double&x){scanf("%lf",&x);}
void rd(long double&x){scanf("%Lf",&x);}
void rd(string&x){cin>>x;}
void rd(char*x){scanf("%s",x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&p:x)rd(p);}
template<typename C,typename...T>void rd(C&a,T&...args){rd(a);rd(args...);}
//istream& operator>>(istream& is,__int128& a){string s;is>>s;a=0;int i=0;bool neg=false;if(s[0]=='-')neg=true,i++;for(;i<s.size();i++)a=a*10+s[i]-'0';if(neg)a*=-1;return is;}
//ostream& operator<<(ostream& os,__int128 a){bool neg=false;if(a<0)neg=true,a*=-1;ll high=(a/(__int128)1e18);ll low=(a-(__int128)1e18*high);string res;if(neg)res+='-';if(high>0){res+=to_string(high);string temp=to_string(low);res+=string(18-temp.size(),'0');res+=temp;}else res+=to_string(low);os<<res;return os;}

int solveOdd(int t, vector<int> &a){ // O(n)
	if(sz(a)==1){
		if(t==0){
			if(a[0]%2==0){
				return 0;
			}
			return 1;
		}
		else{
			if(a[0]%2==1){
				return 0;
			}
			return 1;
		}
	}
	if(t==1)return 1; // Bob wins
	int cntChain=-1;
	for(auto p:a){
		if((p%2)==0){
			if(cntChain==-1){
				cntChain=0;
				continue;
			}
			if(cntChain%2==0){
				return 0; // Alice wins
			}
			cntChain=0;
		}
		else{
			if(cntChain==-1){
				cntChain=0;
			}
			cntChain++;
		}
	}
	return 1; // Bob wins
}
vector<int> applyOp(vector<int> &a,int pos,char op){ // O(N)
	vector<int> ans;
	ans.reserve(sz(a)-1);
	for(int i=0;i<sz(a);i++){
		if((i+1)==pos){
			if(op=='+'){
				ans.pb((a[i]+a[i+1])%2);
			}
			else{
				ans.pb((a[i]*a[i+1])%2);
			}
			i++;
		}
		else{
			ans.pb(a[i]);
		}
	}
	return ans;
}
vector<char> ops={'+','*'};
int solveEven(int t,vector<int> &a){ // O(n^2)
	if(t==0)return 0;
	for(int i=1;i<sz(a);i++){
		for(auto p:ops){
			vector<int> sl=applyOp(a,i,p);
			if(solveOdd(t^1,sl)==1){
				return 0;
			}
		}
	}
	return 1;
}
int solve(int t,vector<int> &a){ //O(n^2)
	if(sz(a)%2==1){
		return solveOdd(t,a);
	}
	return solveEven(t,a);
}
int main()
{
	int n=ri(),t=ri();
	vector<int> a(n);
	rd(a);
	if(solve(t,a)){
		printf("Bob\n");
		fflush(stdout);
		int x;
		string s;
		cin >> x >> s;
		a=applyOp(a,x,s[0]);
		t^=1;
	}
	else{
		printf("Alice\n");
		fflush(stdout);
	}
	while(sz(a)!=1){
		if(sz(a)%2==1){ // O(n)
			bool ok=0;
			for(int i=1;i<sz(a);i++){
				if(a[i]==1&&a[i-1]==1){
					printf("%i +\n",i);
					fflush(stdout);
					a=applyOp(a,i,'+');
					ok=1;
					break;
				}
			}
			if(!ok){
				for(int i=1;i<sz(a);i++){
					if(a[i]!=a[i-1]){
						printf("%i *\n",i);
						fflush(stdout);
						a=applyOp(a,i,'*');
						ok=1;
						break;
					}
				}
				if(!ok){
					assert(0);
				}
			}
		}
		/*else{
			int last0=-1;
			bool ok=0;
			for(int i=0;i<sz(a);i++){ //my job is to remove 0s
				if(a[i]==0){
					if((i-last0+1)%2==0){
						if(last0!=-1){
							if(last0!=0){
								assert(a[last0-1]==1);
								ok=1;
								printf("%i +\n",last0);
								fflush(stdout);
								a=applyOp(a,last0,'+');
								break;
							}
							if(last0+1!=i){
								assert(a[last0+1]==1);
								ok=1;
								printf("%i +\n",last0+1);
								fflush(stdout);
								a=applyOp(a,last0+1,'+');
								break;
							}
						}
						if(i!=sz(a)-1&&a[i+1]==1){
							ok=1;
							printf("%i +\n",i+1);
							fflush(stdout);
							a=applyOp(a,i+1,'+');
							break;
						}
						if(i!=0&&a[i-1]==1){
							ok=1;
							printf("%i +\n",i);
							fflush(stdout);
							a=applyOp(a,i,'+');
							break;
						}
						assert(0);
					}
					last0=i;
				}
			}
			if(!ok){
				printf("1 +\n");
				fflush(stdout);
				a=applyOp(a,1,'+');
			}
		}*/
		else{
			bool found = 0;
			for(int i=1;i<sz(a);i++){ // O(n^2)
				for(auto p:ops){
					vector<int> sl=applyOp(a,i,p);
					if(solve(t^1,sl)==1){ // O(n)
						found = 1;
						printf("%i %c\n",i,p);
						fflush(stdout);
						a=sl;
						i=sz(a);
						break;
					}
				}
			}
			if(!found)assert(0);
		}
		if(sz(a)==1)break;
		int x;
		string s;
		cin >> x >> s;
		a=applyOp(a,x,s[0]);
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3760kb

input:

4 1
0 1 0 1
1 *
1

output:

Alice
1 +
1 +

result:

ok The player wins!

Test #2:

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

input:

4 0
1 0 1 0
1 *
1

output:

Alice
1 +
1 *

result:

ok The player wins!

Test #3:

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

input:

5 1
1 1 1 0 0
4 +
1 +
1

output:

Bob
1 +
1 *

result:

ok The player wins!

Test #4:

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

input:

3 0
1 1 1
1 +
1

output:

Bob
1 +

result:

ok The player wins!

Test #5:

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

input:

3 1
1 0 1
1 *
1

output:

Bob
1 *

result:

ok The player wins!

Test #6:

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

input:

3 0
1 0 1
1 *
1

output:

Bob
1 +

result:

ok The player wins!

Test #7:

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

input:

2 1
0 1
1

output:

Alice
1 +

result:

ok The player wins!

Test #8:

score: -100
Runtime Error

input:

499 0
0 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 0 1 1 1 1 1 1 1 0 1 0 ...

output:

Bob
1 +
1 +
1 +
2 +
4 +
8 +
10 +
10 +
12 +
12 +
14 +
18 +
18 +
18 +
18 +
20 +
20 +
22 +
22 +
24 +
24 +
24 +
26 +
26 +
26 +
26 +
28 +
28 +
28 +
30 +
30 +
32 +
34 +
36 +
38 +
38 +
46 +
46 +
46 +
46 +
46 +
50 +
52 +
52 +
52 +
56 +
56 +
56 +
58 +
58 +
60 +
64 +
66 +
68 +
68 +
70 +
72 +
74 +
74 +
76 +
76...

result: