QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#875989#9871. Just another Sorting Problemfrankly6#WA 0ms3584kbC++171.4kb2025-01-30 15:24:312025-01-30 15:24:31

Judging History

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

  • [2025-01-30 15:24:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3584kb
  • [2025-01-30 15:24:31]
  • 提交

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 if(loop.size()==0) cout << "Alice\n";
            else cout << "Bob\n";
        }
    }
    return (0-0);
}

详细

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'