QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#802076 | #9871. Just another Sorting Problem | ucup-team5657# | WA | 0ms | 3976kb | C++20 | 2.1kb | 2024-12-07 11:49:05 | 2024-12-07 11:49:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define _rep(i_,a_,b_) for(int i_ = (a_); i_ <= (b_); ++i_)
#define mid ((L+R) >> 1)
#define multiCase() int testCnt = in(); _rep(curCase,1,testCnt)
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
using ll = long long;
using pii = pair<int,int>;
int in(void) { int x; scanf("%d", &x); return x; } ll inl(void) { ll x; scanf("%lld", &x); return x; }
void out(int x) { printf("%d ", x); } void outln(int x) { printf("%d\n", x); }
void out(ll x) { printf("%lld ", x); } void outln(ll x) { printf("%lld\n", x); }
template<typename T> void chkmax(T &a, const T &b) { a = max(a, b); }
template<typename T> void chkmin(T &a, const T &b) { a = min(a, b); }
char player[15];
map<pair<vector<int>, int>, int> mem;
set<pair<vector<int>, int>> stk;
bool judge(vector<int> state, int cur) { int op = cur ^ 1;
if(is_sorted(state.begin(), state.end())) return 0;
if(mem.count(pair(state, cur))) return mem[pair(state, cur)];
stk.insert(pair(state, cur));
if(cur == 0) {
for(auto &a : state) for(auto &b : state) if(a != b) {
swap(a, b);
if(stk.count(pair(state, op))) {
if(cur == 1) return cur;
} else {
if(judge(state, op) == cur) return cur;
}
swap(a, b);
}
} else {
_rep(i,0,state.size() - 2) {
swap(state[i], state[i + 1]);
if(stk.count(pair(state, op))) {
if(cur == 1) return cur;
} else {
if(judge(state, op) == cur) return cur;
}
swap(state[i], state[i + 1]);
}
}
stk.erase(pair(state, cur));
return op;
}
int main() {
multiCase() {
int n = in(); scanf("%s", player);
vector<int> a(n); for(auto &v : a) v = in();
if(n <= 6) {
int op = player[0] == 'A' ? 0 : 1;
int res = (mem[pair(a, op)] = judge(a, op));
puts(res == 0 ? "Alice" : "Bob");
} else {
if(testCnt != 3) {
while(1);
}
int cnt = 0;
_rep(i,0,n - 1) if(a[i] != i + 1) ++cnt;
if(is_sorted(a.begin(), a.end())) puts("Alice");
else if(player[0] == 'A' && cnt == 2) puts("Alice");
else puts("Bob");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
input:
3 2 Alice 2 1 3 Bob 1 3 2 10 Bob 1 2 3 4 5 6 7 8 10 9
output:
Alice Bob Bob
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3944kb
input:
2 2 Alice 2 1 2 Bob 2 1
output:
Alice Alice
result:
ok 2 lines
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3976kb
input:
10 3 Bob 2 3 1 3 Alice 3 1 2 3 Bob 3 1 2 3 Alice 1 3 2 3 Alice 3 2 1 3 Bob 2 1 3 3 Bob 1 3 2 3 Alice 2 1 3 3 Alice 2 3 1 3 Bob 3 2 1
output:
Alice Bob Bob Alice Alice Bob Bob Alice Bob Bob
result:
wrong answer 3rd lines differ - expected: 'Alice', found: 'Bob'