QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#808879 | #9871. Just another Sorting Problem | ucup-team1004# | TL | 148ms | 4008kb | C++20 | 2.2kb | 2024-12-11 09:12:43 | 2024-12-11 09:12:44 |
Judging History
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];
map<vector<int>,int> ans[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]);
// gdb(A[0],A[1],A[2]);
int op=dfs(A,0);
swap(A[x],A[y]);
if(op) return f[op].erase(A),1;
}
f[op].erase(A);
return 0;
}else{
for(int x=1;x<n;x++){
swap(A[x],A[x-1]);
int op=dfs(A,1);
swap(A[x],A[x-1]);
if(!op) return f[op].erase(A),0;
}
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;
}
if(ans[op].count(A)){
puts(ans[op][A]?"Alice":"Bob");
return;
}
f[0].clear();f[1].clear();
ans[op][A]=dfs(A,op);
puts(ans[op][A]?"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: 4008kb
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: 3924kb
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: 3932kb
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: 0
Accepted
time: 148ms
memory: 3976kb
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:
Bob Bob Bob Bob Bob Bob Alice Alice Bob Bob Alice Bob Bob Bob Bob Alice Bob Bob Bob Bob Bob Bob Alice Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Alice Bob Bob Bob Bob Bob
result:
ok 46 lines
Test #5:
score: -100
Time Limit Exceeded
input:
238 5 Alice 5 4 2 1 3 5 Bob 1 4 5 3 2 5 Bob 3 1 4 5 2 5 Alice 1 4 2 5 3 5 Bob 3 2 5 4 1 5 Alice 1 3 4 2 5 5 Bob 2 3 4 5 1 5 Bob 1 4 3 2 5 5 Bob 2 4 1 3 5 5 Bob 3 4 2 5 1 5 Alice 5 3 2 1 4 5 Bob 1 2 4 3 5 5 Alice 1 4 5 2 3 5 Alice 5 3 4 1 2 5 Alice 3 4 2 1 5 5 Alice 2 5 1 4 3 5 Alice 1 3 5 4 2 5 Alic...