Submission #520013

#TimeUsernameProblemLanguageResultExecution timeMemory
520013KoDPolitičari (COCI20_politicari)C++17
70 / 70
51 ms61132 KiB
#include <bits/stdc++.h> using std::vector; using std::array; using std::pair; using std::tuple; using ll = long long; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int N; ll K; std::cin >> N >> K; vector A(N, vector(N, 0)); for (auto& v : A) { for (auto& x : v) { std::cin >> x; x -= 1; } } array<vector<int>, 60> to; to[0] = vector(N * N, 0); for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if (i != j) { to[0][i * N + j] = A[i][j] * N + i; } } } for (int k = 0; k + 1 < 60; ++k) { to[k + 1] = vector(N * N, 0); for (int i = 0; i < N * N; ++i) { to[k + 1][i] = to[k][to[k][i]]; } } if (K == 1) { std::cout << 1 << '\n'; return 0; } K -= 2; int ans = 1 * N + 0; for (int k = 0; k < 60; ++k) { if (K >> k & 1) { ans = to[k][ans]; } } std::cout << ans / N + 1 << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...