# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
209988 | 2020-03-16T08:00:22 Z | SamAnd | Političari (COCI20_politicari) | C++17 | 38 ms | 2424 KB |
#include <bits/stdc++.h> using namespace std; #define m_p make_pair const int N = 502; int n; long long k; int a[N][N]; bool c[N][N]; int main() { scanf("%d%lld", &n, &k); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { scanf("%d", &a[i][j]); } } if (k == 1) { printf("1\n"); return 0; } k -= 2; vector<pair<int, int> > v; pair<int, int> u = m_p(2, 1); c[u.first][u.second] = true; v.push_back(u); while (k--) { pair<int, int> h = m_p(a[u.first][u.second], u.first); if (c[h.first][h.second]) { for (int i = 0; i < v.size(); ++i) { if (v[i] == h) { k %= (v.size() - i); printf("%d\n", v[i + k].first); return 0; } } } u = h; c[u.first][u.second] = true; v.push_back(u); } printf("%d\n", u.first); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 11 ms | 1016 KB | Output is correct |
3 | Correct | 25 ms | 1912 KB | Output is correct |
4 | Correct | 31 ms | 2168 KB | Output is correct |
5 | Correct | 37 ms | 2424 KB | Output is correct |
6 | Correct | 37 ms | 2424 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 7 ms | 760 KB | Output is correct |
9 | Correct | 13 ms | 1144 KB | Output is correct |
10 | Correct | 34 ms | 2192 KB | Output is correct |
11 | Correct | 38 ms | 2424 KB | Output is correct |
12 | Correct | 38 ms | 2424 KB | Output is correct |
13 | Correct | 5 ms | 504 KB | Output is correct |
14 | Correct | 7 ms | 760 KB | Output is correct |