QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#459225#8838. Jesse's Jobucup-team1134#WA 0ms3644kbC++231.3kb2024-06-29 23:45:472024-06-29 23:45:58

Judging History

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

  • [2024-06-29 23:45:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3644kb
  • [2024-06-29 23:45:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;

void solve(){
    int N;cin>>N;
    vector<int> P(N),seen(N);
    for(int i=0;i<N;i++){
        cin>>P[i];P[i]--;
    }
    vector<vector<int>> ans;
    
    for(int i=0;i<N;i++){
        if(seen[i]) continue;
        ans.push_back({});
        int now=i;
        while(1){
            if(seen[now]) break;
            seen[now]=true;
            ans.back().push_back(now);
            now=P[now];
        }
    }
    
    if(si(ans)>=2){
        cout<<N<<"\n";
        cout<<si(ans[0])<<"\n";
        for(int x:ans[0]) cout<<x+1<<" ";
        cout<<"\n";
    }else{
        cout<<N-2<<"\n";
        cout<<1<<"\n";
        cout<<ans[0][0]+1<<"\n";
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        solve();
    }
}


详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3644kb

input:

3
2
2 1
4
2 1 4 3
6
3 5 4 2 6 1

output:

0
1
1
4
2
1 2 
4
1
1

result:

wrong answer Participant didn't find permutation (test case 3)