#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN=500;
int n, nxt[mxN*mxN][60];
ll k;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k, --k;
for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) {
cin >> nxt[n*j+i][0], --nxt[n*j+i][0];
if (i==j) continue;
nxt[n*j+i][0]+=n*i;
}
for (int j=1; j<60; ++j) for (int i=0; i<n*n; ++i) if (i/n!=i%n) nxt[i][j]=nxt[nxt[i][j-1]][j-1];
int cur=1;
for (int j=0; j<60; ++j) {
if ((k>>j)&1) {
cur=nxt[cur][j];
}
}
int ans=(cur/n)+1;
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
33 ms |
11648 KB |
Output is correct |
3 |
Correct |
157 ms |
38012 KB |
Output is correct |
4 |
Correct |
208 ms |
48632 KB |
Output is correct |
5 |
Correct |
276 ms |
60032 KB |
Output is correct |
6 |
Correct |
257 ms |
60152 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
11 ms |
4608 KB |
Output is correct |
9 |
Correct |
38 ms |
13056 KB |
Output is correct |
10 |
Correct |
216 ms |
48632 KB |
Output is correct |
11 |
Correct |
268 ms |
60028 KB |
Output is correct |
12 |
Correct |
276 ms |
60152 KB |
Output is correct |
13 |
Correct |
2 ms |
896 KB |
Output is correct |
14 |
Correct |
11 ms |
4608 KB |
Output is correct |