# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
749927 | Trunkty | Političari (COCI20_politicari) | C++14 | 239 ms | 128432 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.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |