# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
640202 | iee | Političari (COCI20_politicari) | C++17 | 47 ms | 6436 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 int long long
using namespace std;
const int N = 1005;
int n, k, a[N][N], vis[N][N];
vector<pair<int, int>> v;
void Ins(int x, int y) {
vis[x][y] = 1;
v.emplace_back(x, y);
}
signed main() {
cin >> n >> k;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
cin >> a[i][j];
Ins(0, 1), Ins(1, 2);
pair<int, int> las;
while (true) {
int x = v.size() - 1, fi = v[x].first, se = v[x].second;
if (vis[se][a[se][fi]]) {
las = {se, a[se][fi]};
break;
}
Ins(se, a[se][fi]);
}
reverse(v.begin(), v.end());
while (k > 1 && !v.empty() && v.back() != las)
v.pop_back(), k -= 1;
reverse(v.begin(), v.end());
if (!k) {
cout << v[0].second;
return 0;
}
int pos = k % v.size() - 1;
if (pos < 0) pos += (int) v.size();
cout << v[pos].second;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |