Submission #883808

# Submission time Handle Problem Language Result Execution time Memory
883808 2023-12-06T05:54:03 Z vjudge1 Političari (COCI20_politicari) C++17
35 / 70
13 ms 2396 KB
#ifndef Local
    #pragma GCC optimize("O3,unroll-loops")
    const int lim=2e5+100;
#else
    const int lim=2e3+100;
#endif

#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define pb push_back

const int mod=1e9+7;
using pii=pair<int,int>;

inline void solve(){
    int n,k;
    cin>>n>>k;
    int a[n+1][n+1];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
        }
    }
    unordered_map<int,int>all,rev;
    int now=2,past=1,time=2;
    while(!all.count(now*n+past)){
        all[now*n+past]=time;
        rev[time]=now;
        past=a[now][past];
        swap(now,past);
        time++;
    }
    int loopy=all[now*n+past];
    k-=loopy;
    k%=time-loopy;
    k+=loopy;
    cout<<rev[k]<<"\n";
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
#ifdef Local  
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#else
    //freopen("grass.in","r",stdin);
    //freopen("grass.out","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Incorrect 1 ms 860 KB Output isn't correct
4 Incorrect 2 ms 1116 KB Output isn't correct
5 Incorrect 2 ms 1368 KB Output isn't correct
6 Incorrect 2 ms 1372 KB Output isn't correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Correct 1 ms 584 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 10 ms 1884 KB Output is correct
11 Correct 13 ms 2396 KB Output is correct
12 Correct 13 ms 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct