QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#405530#7863. Parity Gamednialh#RE 1ms3664kbC++203.2kb2024-05-06 05:41:102024-05-06 05:41:10

Judging History

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

  • [2024-05-06 05:41:10]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3664kb
  • [2024-05-06 05:41:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define sq(a) ((a)*(a))

#define MOO(i,a,b) for (int i=a; i<b; i++)
#define M00(i,a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define per(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a,b) for (int i=a; i<b; i++)

#define FOR(i,a,b) for (int i=a; i<b; i++)
#define F0R(i,a) for (int i=0; i<a; i++)
#define ROF(i,a,b) for (int i = (b)-1; i >= a; i--)
#define R0F(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << endl, 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << endl;
#define _ << " _ " <<

#define int long long

template<class T> bool ckmin(T&a, T&b) { bool B = a > b; a = min(a,b); return B; }
template<class T> bool ckmax(T&a, T&b) { bool B = a < b; a = max(a,b); return B; }

typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ld,ld> pld;
typedef complex<ld> cd;

typedef vector<int> vi;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;

const ld PI = acos(-1.0);
const ld EPS = 1e-7;
const int MOD = 1e9+7;

// Really should be changed to a modular int class 
int POW(int b, int e) {
	int r = 1;
	while(e) {
		if(e % 2 == 1) {
			r *= b;
			r %= MOD;
		}
		e /= 2;
		b *= b;
		b %= MOD;
	}
	return r;
}
int INV(int a) {
	return POW(a, MOD-2);
}
//Constants and Variables here

bool win(int player, vi &arr) {
	int n = arr.size();
	if(n == 1) {
		return arr[0] == player;
	}
	if(player == 0) {
		if(arr.size() % 2 == 0) return true;
		M00(i, (n+1) / 2) {
			if(arr[2 * i] == 0) return true;
		}
		return false;
	} else {
		if(arr.size() % 2 == 1) return false;
		int cnt = 0;
		if(arr[0] == 0) cnt++;
		if(arr[n-1] == 0) cnt++;
		M00(i, n-1) {
			if(arr[i] == 0 && arr[i+1] == 0) cnt++;
		}
		M00(i, n) {
			if(arr[i] == 0) continue;
			int j = i;
			while(j < n-1 && arr[j+1] == 1) j++;
			if((j - i) % 2 == 1) cnt++;
		}
		return cnt <= 1;
	}
}

const string SS = "*+";

vi move(vi arr, int p, char opp) {
	vi narr;
	int n = arr.size();
	M00(j, p)
	narr.pb(arr[j]);
	if (opp == '+')
	{
		narr.pb((arr[p] + arr[p + 1]) % 2);
	}
	else
	{
		narr.pb((arr[p] * arr[p + 1]) % 2);
	}
	MOO(j, p + 2, n)
	{
		narr.pb(arr[j]);
	}
	return narr;
}

vi make_move(int player, vi &arr) {
	int n = arr.size();
	M00(c, 2) {
		M00(i, n-1) {
			vi narr = move(arr, i, SS[c]);
			if(!win(1 - player, narr)) {
				cout << i + 1 << " " << SS[c] << endl;
				return narr;
			}
		}
	}
	assert(false);
}

int32_t main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int n, t;
	cin >> n >> t;
	vi arr(n);
	M00(i, n) cin >> arr[i];
	
	if(win(t, arr)) {
		cout << "Alice" << endl;
		arr = make_move(t, arr);
	} else {
		cout << "Bob" << endl;
		t = 1- t;
	}
	while(arr.size() > 1) {
		int p; char c;
		cin >> p >> c;
		p -= 1;
		arr = move(arr, p, c);
		if(arr.size() > 1) {
			arr = make_move(t, arr);
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3664kb

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

input:

4 0
1 0 1 0
1 +
1

output:

Alice
1 *
1 *

result:

ok The player wins!

Test #3:

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

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

input:

3 0
1 1 1
1 +
1

output:

Bob
1 +

result:

ok The player wins!

Test #5:

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

input:

3 1
1 0 1
1 *
1

output:

Bob
1 *

result:

ok The player wins!

Test #6:

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

input:

3 0
1 0 1
1 *
1

output:

Bob
1 +

result:

ok The player wins!

Test #7:

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

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:

Alice
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 *
1 ...

result: