Submission #638386

# Submission time Handle Problem Language Result Execution time Memory
638386 2022-09-05T17:36:13 Z NeroZein Političari (COCI20_politicari) C++14
35 / 70
1000 ms 2188 KB
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

const int N = 505;
int n, k, g[N][N], vis[N][N]; 

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            cin>>g[i][j];
    
    if (k == 1)return cout<<1,0;

    k-=2;
    vis[1][2] = 1; 
    pair<int,int>cur = {2,1};

    while(k){
        k--;
        pair<int,int> to = {g[cur.first][cur.second],cur.first};
        if (vis[to.first][to.second]&&k>2500){
            int len = vis[cur.first][cur.second]-vis[to.first][to.second]+1;
            k %= len;
        }
        cur = to;
    }
    cout<<cur.first;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Execution timed out 1081 ms 340 KB Time limit exceeded
3 Execution timed out 1093 ms 340 KB Time limit exceeded
4 Execution timed out 1084 ms 340 KB Time limit exceeded
5 Execution timed out 1097 ms 340 KB Time limit exceeded
6 Execution timed out 1083 ms 340 KB Time limit exceeded
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 13 ms 1872 KB Output is correct
11 Correct 18 ms 2120 KB Output is correct
12 Correct 16 ms 2188 KB Output is correct
13 Execution timed out 1086 ms 340 KB Time limit exceeded
14 Execution timed out 1075 ms 596 KB Time limit exceeded