QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#801889 | #9871. Just another Sorting Problem | ucup-team5657# | WA | 0ms | 3652kb | C++14 | 2.1kb | 2024-12-07 10:31:00 | 2024-12-07 10:31:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define mkp make_pair
#define pb emplace_back
#define popcnt __builtin_popcountll
const ll mod = 998244353;
inline ll read(){
ll x=0, f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0' && ch<='9') x=x*10+ch-'0', ch=getchar();
return x*f;
}
inline int lg2(int x){ return 31^__builtin_clz(x); }
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
inline ll qpow(ll a,ll b){
ll ans=1, base=a;
while(b){
if(b&1) ans=ans*base%mod;
base=base*base%mod; b>>=1;
}
return ans;
}
void init(){ }
int n,p[100005],seq[100005],cnt;
string S;
unordered_map<int,int>mp;
int dfs(vector<int> v, int f){
ll id=0, flg=1;
for(int i=1;i<=n;i++) {
id=id*(n+1)+v[i-1];
flg&=(v[i-1]==i);
}
if(flg) return mp[id]=1;
id = (id<<1) | f;
if(mp.count(id)) return mp[id];
// cout<<"search ";
// for(auto x: v) cout<<x<<" "; cout<<"f = "<<f<<endl;
if(f){ // alice
for(int i=1; i<=n; i++){
for(int j=i+2; j<=n; j++){
swap(v[i-1], v[j-1]);
if(dfs(v, f^1)==1) return mp[id] = 2;
swap(v[i-1], v[j-1]);
}
}
}else{ // bob
for(int i=1; i<n; i++){
swap(v[i], v[i-1]);
if(dfs(v, f^1)==1) return mp[id] = 2;
swap(v[i], v[i-1]);
}
}
return mp[id]=1;
}
void procedure(){
mp.clear();
cin>>n>>S;
string T = (S=="Alice")?"Bob":"Alice";
vector<int>v;
for(int i=1;i<=n;i++) {
int x; cin>>x; v.pb(x);
}
vector<int>q;
for(int i=0;i<n;i++){
if(v[i] != i+1) q.pb(i);
}
// cout<<q.size()<<" ok"<<endl;
if(q.size() == 2 && (S == "Alice" || q[0]+1==q[1]) ){
cout<<S<<"\n";
return;
}
if(n <= 6){
if(dfs(v, S=="Alice")==2){
cout<<S<<"\n";
}else cout<<T<<"\n";
}else{
cout<<T<<"\n";
}
}
int main(){
#ifdef LOCAL
assert(freopen("input.txt","r",stdin));
assert(freopen("output.txt","w",stdout));
#endif
ll T; cin>>T;
init();
while(T--) procedure();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
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: -100
Wrong Answer
time: 0ms
memory: 3652kb
input:
2 2 Alice 2 1 2 Bob 2 1
output:
Alice Bob
result:
wrong answer 2nd lines differ - expected: 'Alice', found: 'Bob'