Submission #210021

# Submission time Handle Problem Language Result Execution time Memory
210021 2020-03-16T11:01:06 Z apostoldaniel854 Političari (COCI20_politicari) C++14
70 / 70
26 ms 2168 KB
/*
https://oj.uz/problem/view/COCI20_politicari
*/


#include <bits/stdc++.h>

using namespace std;


typedef long long ll;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"

const int N = 500;

int politician[1 + N * N + 4];
int nxt[1 + N][1 + N];
int used[1 + N][1 + N];


int main() {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);

    ll k;
    int n;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            cin >> nxt[i][j];
    nxt[1][0] = 2;
    int start, blamed;
    blamed = 0;
    start = 1;
    int step = 0;
    while (used[start][blamed] == 0) {
        used[start][blamed] = ++step;
        politician[step] = start;
        int cur = nxt[start][blamed];
        blamed = start;
        start = cur;
    }
    if (k < used[start][blamed]) {
        cout << politician[k] << "\n";
    }
    else {
        k -= used[start][blamed];
        int period = step - used[start][blamed] + 1;
        cout << politician[used[start][blamed] + k % period] << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 9 ms 1144 KB Output is correct
3 Correct 17 ms 1656 KB Output is correct
4 Correct 21 ms 1912 KB Output is correct
5 Correct 25 ms 2040 KB Output is correct
6 Correct 26 ms 1908 KB Output is correct
7 Correct 5 ms 380 KB Output is correct
8 Correct 6 ms 888 KB Output is correct
9 Correct 11 ms 1272 KB Output is correct
10 Correct 21 ms 1784 KB Output is correct
11 Correct 25 ms 2168 KB Output is correct
12 Correct 25 ms 2168 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 6 ms 888 KB Output is correct