# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
638395 | NeroZein | Političari (COCI20_politicari) | C++14 | 16 ms | 2068 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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, g[N][N], vis[N][N];
long long k;
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[2][1] = 2;
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;
}
vis[g[cur.first][cur.second]][cur.first] = vis[cur.first][cur.second]+1;
cur = to;
}
cout<<cur.first;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |