Submission #749927

#TimeUsernameProblemLanguageResultExecution timeMemory
749927TrunktyPolitičari (COCI20_politicari)C++14
70 / 70
239 ms128432 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll int n,k; int jump[250005][65]; signed main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; if(k<=2){ cout << k << "\n"; return 0; } k -= 2; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ int a; cin >> a; if(a){ jump[(i-1)*n+(j-1)][0] = (a-1)*n+(i-1); } } } for(int j=1;j<=63;j++){ for(int i=0;i<n*n;i++){ jump[i][j] = jump[jump[i][j-1]][j-1]; } } int curr = 1*n+0; for(int j=63;j>=0;j--){ if(k&(1LL<<j)){ curr = jump[curr][j]; } } cout << curr/n+1 << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...