189632025-11-13 18:30:21ercseferencHírlánccpp17Wrong answer 0/80244ms262144 KiB
#include <bits/stdc++.h>
using namespace std;
vector<int>a,hossz;
vector<bool>volt;
vector<vector<int>>sor;
void nez(int x,int y){
    volt[x]=1;
    sor[y].push_back(x); volt[x]=1;
    if(hossz[a[x]]!=0){
        hossz[sor[y][sor[y].size()-1]]=hossz[a[x]]+1;
        for(int i=sor[y].size()-2; i>=0; i--)
            hossz[sor[y][i]]=hossz[sor[y][i+1]]+1;
        sor[y].clear();}
    else if(volt[a[x]]){
        int ind=-1;
        for(int i=0; i<sor[y].size(); i++)
            if(sor[y][i]==a[x]){ind=i; break;}
        for(int i=ind; i<sor[y].size(); i++)
            hossz[sor[y][i]]=sor[y].size()-ind;
        for(int i=ind-1; i>=0; i--)
            hossz[sor[y][i]]=hossz[sor[y][i+1]]+1;
        sor[y].clear();}
    else nez(a[x],y);}
int main()
{
    int n; cin>>n; a.resize(n+1); hossz.resize(n+1);
    volt.resize(n+1); sor.resize(n+1,vector<int>(n+1));
    for(int i=1; i<=n; i++)cin>>a[i];
    for(int i=1; i<=n; i++)if(hossz[i]==0)nez(i,i);
    int maxi=-1, maxind;
    for(int i=1; i<=n; i++){
        if(hossz[i]>maxi){maxi=a[i]; maxind=i;}}
    cout<<maxind<<" "<<maxi;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
subtask20/20
2Wrong answer28ms23604 KiB
3Wrong answer25ms23676 KiB
4Wrong answer29ms23860 KiB
5Wrong answer25ms23832 KiB
6Wrong answer24ms23488 KiB
7Wrong answer27ms22840 KiB
8Wrong answer25ms23984 KiB
9Wrong answer28ms24116 KiB
10Wrong answer17ms16436 KiB
11Wrong answer14ms16180 KiB
12Wrong answer14ms16432 KiB
subtask30/18
13Runtime error238ms262144 KiB
14Runtime error200ms262144 KiB
15Runtime error202ms262144 KiB
16Runtime error238ms262144 KiB
17Runtime error244ms262144 KiB
18Runtime error203ms262144 KiB
19Runtime error237ms262144 KiB
20Runtime error197ms262144 KiB
21Runtime error202ms262144 KiB
22Runtime error240ms262144 KiB
subtask40/42
23Accepted1ms496 KiB
24Wrong answer28ms23604 KiB
25Wrong answer25ms23676 KiB
26Wrong answer29ms23860 KiB
27Wrong answer25ms23832 KiB
28Wrong answer24ms23488 KiB
29Wrong answer27ms22840 KiB
30Wrong answer25ms23984 KiB
31Wrong answer28ms24116 KiB
32Wrong answer17ms16436 KiB
33Wrong answer14ms16180 KiB
34Wrong answer14ms16432 KiB
35Runtime error238ms262144 KiB
36Runtime error200ms262144 KiB
37Runtime error202ms262144 KiB
38Runtime error238ms262144 KiB
39Runtime error244ms262144 KiB
40Runtime error203ms262144 KiB
41Runtime error237ms262144 KiB
42Runtime error197ms262144 KiB
43Runtime error202ms262144 KiB
44Runtime error240ms262144 KiB
45Runtime error200ms262144 KiB
46Runtime error237ms262144 KiB
47Runtime error197ms262144 KiB
48Runtime error238ms262144 KiB
49Runtime error201ms262144 KiB
50Runtime error241ms262144 KiB
51Runtime error238ms262144 KiB
52Runtime error241ms262144 KiB
53Runtime error208ms262144 KiB
54Runtime error196ms262144 KiB