QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#808868#9871. Just another Sorting Problemucup-team1004#WA 1ms4012kbC++202.0kb2024-12-11 09:02:312024-12-11 09:02:36

Judging History

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

  • [2024-12-11 09:02:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4012kb
  • [2024-12-11 09:02:31]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=2e5+5,M=N*4+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,A[N];
char token[10];
map<vector<int>,int> f[2];
int dfs(vector<int> A,int op){
	int flag=0;
	for(int i=0;i<n;i++) if(A[i]^i+1) flag=1;
	if(!flag) return 1;
	// gdb(A[0],A[1],A[2],op);
	if(f[op].count(A)) return 0;
	f[op][A]=0;
	if(op){
		for(int x=0;x<n;x++) for(int y=x+1;y<n;y++){
			swap(A[x],A[y]);
			if(dfs(A,0)) return f[op].erase(A),1;
			swap(A[x],A[y]);
		}
		f[op].erase(A);
		return 0;
	}else{
		for(int x=1;x<n;x++){
			swap(A[x],A[x-1]);
			if(!dfs(A,1)) return f[op].erase(A),0;
			swap(A[x],A[x-1]);
		}
		f[op].erase(A);
		return 1;
	}
}
void Solve(){
	scanf("%d%s",&n,token+1);
	int op=(token[1]=='A');
	vector<int> A(n);
	for(int i=1;i<=n;i++) scanf("%d",&A[i-1]);
	int cnt=0;
	for(int i=1;i<=n;i++) if(A[i-1]^i) cnt++;
	if(op&&cnt==2){
		puts("Alice");
		return;
	}
	if(!op&&n>4){
		puts("Bob");
		return;
	}
	f[0].clear();f[1].clear();
	puts(dfs(A,op)?"Alice":"Bob");
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Test #1:

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

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

input:

2
2 Alice
2 1
2 Bob
2 1

output:

Alice
Alice

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3888kb

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'