QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#875952 | #9871. Just another Sorting Problem | frankly6# | WA | 0ms | 3584kb | C++17 | 1.4kb | 2025-01-30 14:45:16 | 2025-01-30 14:45:17 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int MX=100020;
int T, N;
int ar[MX], fa[MX], siz[MX];
vector<int> loop;
int read()
{
int r=0, f=1; char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
return r*f;
}
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void merge(int x, int y)
{
x=find(x); y=find(y);
if(x==y) return;
if(x>y) swap(x,y);
fa[y]=x; siz[x]+=siz[y];
}
int main()
{
// freopen("testdata.in","r",stdin);
T=read();
while(T--)
{
N=read(); string s; cin >> s;
for(int i=1;i<=N;i++)
{
ar[i]=read();
fa[i]=i; siz[i]=1;
}
for(int i=1;i<=N;i++)
if(i!=ar[i]) merge(i,ar[i]);
loop.clear();
for(int i=1;i<=N;i++)
{
fa[i]=find(i);
if(i==fa[i]&&siz[i]!=1) loop.push_back(siz[i]);
// cout << siz[i] << " ";
}
sort(loop.begin(),loop.end(),greater<int>());
// cout << "loop[0]=" << loop[0] << '\n';
if(N==2) cout << "Alice\n";
else
{
if(loop.size()==1&&loop[0]==2&&s[0]=='A') cout << "Alice\n";
else cout << "Bob\n";
}
}
return (0-0);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 3584kb
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: 3584kb
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:
Bob Bob Bob Alice Alice Bob Bob Alice Bob Bob
result:
wrong answer 1st lines differ - expected: 'Alice', found: 'Bob'