Submission #520013

# Submission time Handle Problem Language Result Execution time Memory
520013 2022-01-28T06:06:24 Z KoD Političari (COCI20_politicari) C++17
70 / 70
51 ms 61132 KB
#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 time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 10 ms 11676 KB Output is correct
3 Correct 33 ms 38464 KB Output is correct
4 Correct 40 ms 49352 KB Output is correct
5 Correct 51 ms 61124 KB Output is correct
6 Correct 51 ms 61080 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 5 ms 4556 KB Output is correct
9 Correct 11 ms 13388 KB Output is correct
10 Correct 40 ms 49352 KB Output is correct
11 Correct 49 ms 61132 KB Output is correct
12 Correct 49 ms 61044 KB Output is correct
13 Correct 1 ms 844 KB Output is correct
14 Correct 4 ms 4556 KB Output is correct