Submission #583203

# Submission time Handle Problem Language Result Execution time Memory
583203 2022-06-25T04:59:26 Z AGE Političari (COCI20_politicari) C++14
65 / 70
50 ms 3164 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define int long long

using namespace std;
const int N=1e6,M=2e3,mod=1e9+7;
int a[501][501];
map<pair<int,int>,int>vis;
main()
{
    int n,m;
    cin>>n>>m;

    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>a[i][j];

    vector<pair<int,int>>v;
    v.pb({0,1});
    v.pb({1,2});

    vis[{0,1}]=1;
    vis[{1,2}]=1;

    pair<int,int>ans;
    while(1){

        int x=v.size()-1;

        if(vis[{v[x].S,a[v[x].S-1][v[x].F-1]}]==1){
            ans.F=v[x].S;
            ans.S=a[v[x].S-1][v[x].F-1];
            break;
        }

        vis[{v[x].S,a[v[x].S-1][v[x].F-1]}]=1;
        v.pb({v[x].S,a[v[x].S-1][v[x].F-1]});

    }


    reverse(v.begin(),v.end());
    while(((*v.rbegin()).F!=ans.F||(*v.rbegin()).S!=ans.S)&&m>0)
        v.pop_back(),m--;


    reverse(v.begin(),v.end());

    int xx=m%v.size();

    if(xx==0)
        xx=v.size();

    xx--;

    cout<<v[xx].S<<endl;
    return 0;
}

Compilation message

politicari.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 13 ms 1364 KB Output is correct
3 Correct 33 ms 2392 KB Output is correct
4 Correct 39 ms 2764 KB Output is correct
5 Correct 47 ms 3160 KB Output is correct
6 Correct 48 ms 3164 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Correct 5 ms 856 KB Output is correct
9 Correct 13 ms 1484 KB Output is correct
10 Correct 48 ms 2796 KB Output is correct
11 Correct 49 ms 3096 KB Output is correct
12 Correct 50 ms 3160 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 4 ms 852 KB Output is correct