QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#802173#9871. Just another Sorting Problemucup-team5657#TL 0ms3972kbC++202.4kb2024-12-07 12:35:232024-12-07 12:35:24

Judging History

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

  • [2024-12-07 12:35:24]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3972kb
  • [2024-12-07 12:35:23]
  • 提交

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;
	debug("J %d %d %d %d\n", state[0], state[1], state[2], cur);
	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))) {
			} else {
				if(judge(state, op) == cur) {
				swap(a, b);
	stk.erase(pair(state, 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) {

			swap(state[i], state[i + 1]);
	stk.erase(pair(state, cur));
				return cur;
				}
			} else {
				if(judge(state, op) == cur) {
					debug("i = %d\n", i);
			swap(state[i], state[i + 1]);
			stk.erase(pair(state, 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 <= 5) {
			int op = player[0] == 'A' ? 0 : 1;
			stk.clear();
			int res = (mem[pair(a, op)] = judge(a, op));
			puts(res == 0 ? "Alice" : "Bob");
		} else {
			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;
}

詳細信息

Test #1:

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

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

input:

2
2 Alice
2 1
2 Bob
2 1

output:

Alice
Alice

result:

ok 2 lines

Test #3:

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

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
Alice
Alice
Alice
Bob
Bob
Alice
Bob
Bob

result:

ok 10 lines

Test #4:

score: -100
Time Limit Exceeded

input:

46
4 Alice
4 1 3 2
4 Bob
4 1 3 2
4 Bob
3 2 4 1
4 Bob
2 4 1 3
4 Bob
1 4 3 2
4 Bob
4 1 2 3
4 Alice
1 2 4 3
4 Alice
3 2 1 4
4 Bob
2 1 4 3
4 Bob
4 3 1 2
4 Alice
1 3 2 4
4 Bob
3 1 4 2
4 Bob
1 3 2 4
4 Alice
2 4 1 3
4 Bob
2 1 3 4
4 Alice
2 1 3 4
4 Bob
4 2 3 1
4 Bob
3 4 2 1
4 Alice
4 1 2 3
4 Bob
2 4 3 1
4 B...

output:


result: