QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#221426 | #6642. (1, 2) Nim | Nerovix# | WA | 4ms | 3644kb | C++20 | 2.0kb | 2023-10-21 13:20:20 | 2023-10-21 13:20:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define Mp make_pair
#define SZ(x) (int((x).size()))
typedef pair<int, int> pii;
typedef vector<int> vi;
map<pair<vi, int>, int> mp;
int f(vi ve, int who) {
sort(ve.begin(), ve.end(), greater<int>());
while(SZ(ve) && ve.back() == 0) ve.pop_back();
if(SZ(ve) == 0) return 0;
if(SZ(ve) == 1) return 1;
if(mp.find(Mp(ve, who)) != mp.end()) return mp[Mp(ve, who)];
for(int i = 0; i < SZ(ve); i++) {
for(int j = 1; j <= ve[i]; j++) {
ve[i] -= j;
if(f(ve, (who + 1) % 3) == (who == 1)) {
ve[i] += j;
return mp[Mp(ve, who)] = 1;
}
ve[i] += j;
}
}
return mp[Mp(ve, who)] = 0;
}
void dfs(int x, int lim, vi ve) {
if(x == lim) {
if(f(ve, 0) == 1) {
for(auto i : ve)
printf("%d ", i);
puts("");
}
return;
}
for(int i = (x == 0 ? 0 : ve.back()); i <= 3; i++) {
ve.pb(i);
dfs(x + 1, lim, ve);
ve.pop_back();
}
}
void solve() {
int n;
cin >> n;
if(n == 1) {
cout << "Sprague\n";
return;
}
int cnt1 = 0, cnt2 = 0;
for(int i = 0; i < n; i++) {
int a;
cin >> a;
if(a == 1) cnt1++;
else cnt2++;
}
if(cnt2) {
if(cnt2 > 1) {
cout << "Grundy\n";
} else {
if(cnt1 % 3 != 1) {
cout << "Sprague\n";
} else {
cout << "Grundy\n";
}
}
} else {
if(cnt1 % 3 == 1) {
cout << "Sprague\n";
} else {
cout << "Grundy\n";
}
}
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
// dfs(0, 12, {});
int _; for(cin >> _; _; _--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
3 2 1 2 1 5 4 1 7 2 9
output:
Grundy Sprague Grundy
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 4ms
memory: 3644kb
input:
11337 9 4 1 2 3 2 4 3 2 3 10 1 7 1 5 1 2 2 2 1 3 9 1 3 7 3 3 1 1 3 2 12 1 1 2 4 1 2 2 4 2 2 1 4 15 1 3 4 3 1 2 1 4 1 1 1 1 1 1 1 8 3 3 2 2 3 9 1 2 10 2 2 2 2 1 5 1 2 7 2 10 2 2 2 3 2 2 3 5 2 2 7 2 2 6 2 2 3 5 10 1 1 1 3 1 1 1 5 1 1 8 2 2 2 2 5 2 10 1 5 3 10 1 3 1 8 3 4 2 2 1 1 11 1 6 6 4 8 2 4 2 10 ...
output:
Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Sprague Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grundy Grund...
result:
wrong answer 491st lines differ - expected: 'Grundy', found: 'Sprague'