QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#551649#8838. Jesse's JobAA_Surely#WA 2ms9772kbC++231.3kb2024-09-07 17:37:232024-09-07 17:37:23

Judging History

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

  • [2024-09-07 17:37:23]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9772kb
  • [2024-09-07 17:37:23]
  • 提交

answer

#include <bits/stdc++.h>

#define FOR(i, x, n) for(int i = x; i < n; i++)
#define F0R(i, n) FOR(i, 0, n)

#define F first
#define S second
#define PB push_back

#define WTF cout << "WTF" << endl;

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);

using namespace std;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;

const int N = 1e6 + 7;
const int INF = 1e9 + 7;
const int MOD = 998'244'353;

int n;
int ns[N], cyid[N], seen[N], pl[N];
VI ans;

void dfs(int now, int id) {
    cyid[now] = id;
    seen[now] = 1;
    if (!seen[ ns[now] ]) dfs(ns[now], id);
}

void dfs2(int now, int ed) {
    ans.PB(now);
    if (ns[now] == ed) return;
    dfs2(ns[now], ed); }

void solve() {
    ans.clear();

    cin >> n;
    F0R(i, n) {
        cin >> ns[i];
        ns[i]--;
        pl[ ns[i] ] = i;
    }
    fill(seen, seen + n, 0);

    int cnt = 0;
    F0R(i, n) if (!seen[i]) {
        dfs(i, cnt);
        cnt++;
    }

    if (cnt >= 2) {
        cout << n << endl;
        F0R(i, n) 
            if (cyid[i] == 0) 
                ans.PB(i);
    }

    else {
        dfs2(n - 2, n - 1);
    }

    cout << n - 2 << endl;
    cout << ans.size() << endl;
    for(int on : ans) cout << on + 1 << ' ';
    cout << endl;

    return;
}

int main() {
    IOS;

    int t; cin >> t;
    while(t--) solve();
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 9772kb

input:

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

output:

0
1
1 
4
2
2
1 2 
4
1
5 

result:

wrong output format Unexpected end of file - int32 expected (test case 3)