| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 210021 | apostoldaniel854 | Političari (COCI20_politicari) | C++14 | 26 ms | 2168 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
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 | 
|---|---|---|---|---|
| Fetching results... | ||||
