Submission #640202

#TimeUsernameProblemLanguageResultExecution timeMemory
640202ieePolitičari (COCI20_politicari)C++17
70 / 70
47 ms6436 KiB
#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 timeMemoryGrader output
Fetching results...