# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201040 | gs14004 | Političari (COCI20_politicari) | C++17 | 101 ms | 59120 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>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using pi = pair<int, int>;
using lint = long long;
const int MAXN = 250005;
int n; lint k;
int nxt[66][MAXN];
int main(){
scanf("%d %lld",&n,&k);
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
int x; scanf("%d",&x);
if(x){
x--;
nxt[0][i * n + j] = x * n + i;
}
}
}
int pos = n;
k--;
for(int i=1; i<60; i++){
for(int j=0; j<n*n; j++){
nxt[i][j] = nxt[i-1][nxt[i-1][j]];
}
}
for(int i=0; i<60; i++){
if(k & 1) pos = nxt[i][pos];
k >>= 1;
}
cout << (pos % n) + 1 << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |