195242025-12-12 16:27:44szabelrHírlánccpp17Time limit exceeded 38/80601ms12772 KiB
// hirlanc.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <map>
#include <vector>
#include <unordered_map>
#include <set>
using namespace std;

int main()
{
    int n,x,tanulo=1;
    unordered_map <int, int> pairs;
    cin >> n;
    int best[200001];
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        pairs[i]=x;
        best[i] = 0;
    }
    
    int maxi = 0;
    
    for (int i = 1; i <= n; i++)
    {
        if (best[i] == 0) {
            int k = i;
            int og = i;
            vector<int> pontok;
            vector<int> hely(n+1,-1);
            while (hely[k]==-1 and best[k]==0)
            {
                pontok.push_back(k);
                hely[k] = pontok.size() - 1;
                k = pairs[k];
            }
            if (best[k] != 0)
            {
                int a = best[k] + 1;
                for (int y = pontok.size() - 1; y >= 0; y--)
                {
                    best[pontok[y]] = a;
                    a++;
                }
            }
            else
            {
                int size = pontok.size() - hely[k];
                for (int j = hely[k]; j <= pontok.size() - 1; j++)
                {
                    best[pontok[j]] = size;

                }
                int a = best[k] + 1;
                for (int j = hely[k] - 1; j >= 0; j--)
                {
                    best[pontok[j]] = a;
                    a++;

                }
            }
            
            if (best[i] > maxi)
            {
                maxi = best[i];
                tanulo = i;
            }
        }
    }
    cout << tanulo<<" "<<maxi;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
subtask220/20
2Accepted2ms316 KiB
3Accepted2ms316 KiB
4Accepted2ms316 KiB
5Accepted2ms316 KiB
6Accepted2ms316 KiB
7Accepted2ms316 KiB
8Accepted2ms316 KiB
9Accepted2ms316 KiB
10Accepted2ms316 KiB
11Accepted2ms352 KiB
12Accepted2ms316 KiB
subtask318/18
13Accepted358ms10752 KiB
14Accepted209ms10884 KiB
15Accepted187ms10840 KiB
16Accepted133ms10952 KiB
17Accepted143ms12428 KiB
18Accepted144ms11564 KiB
19Accepted146ms11720 KiB
20Accepted159ms11612 KiB
21Accepted159ms12648 KiB
22Accepted142ms12772 KiB
subtask40/42
23Accepted1ms316 KiB
24Accepted2ms316 KiB
25Accepted2ms316 KiB
26Accepted2ms316 KiB
27Accepted2ms316 KiB
28Accepted2ms316 KiB
29Accepted2ms316 KiB
30Accepted2ms316 KiB
31Accepted2ms316 KiB
32Accepted2ms316 KiB
33Accepted2ms352 KiB
34Accepted2ms316 KiB
35Accepted358ms10752 KiB
36Accepted209ms10884 KiB
37Accepted187ms10840 KiB
38Accepted133ms10952 KiB
39Accepted143ms12428 KiB
40Accepted144ms11564 KiB
41Accepted146ms11720 KiB
42Accepted159ms11612 KiB
43Accepted159ms12648 KiB
44Accepted142ms12772 KiB
45Time limit exceeded587ms10844 KiB
46Time limit exceeded588ms10844 KiB
47Time limit exceeded587ms10780 KiB
48Time limit exceeded600ms11800 KiB
49Time limit exceeded583ms10900 KiB
50Time limit exceeded584ms11100 KiB
51Time limit exceeded584ms11116 KiB
52Time limit exceeded601ms10972 KiB
53Time limit exceeded578ms11352 KiB
54Time limit exceeded579ms11544 KiB