# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
848290 | fcmalkcin | Političari (COCI20_politicari) | C++17 | 15 ms | 4184 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.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
const int maxn = 505;
const ll mod = 1e9 + 7;
const ll base = 1e18;
int n;
int mat[maxn][maxn], bio[maxn][maxn], guest[maxn * maxn];
ll k;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> mat[i][j];
--mat[i][j];
}
}
int prev = 0, curr = 1;
guest[1] = 0;
guest[2] = 1;
bio[prev][curr] = 2;
for (int i = 3; (ll)i <= k; ++i) {
int nxt = mat[curr][prev];
prev = curr;
curr = nxt;
if (bio[prev][curr] == 0) {
bio[prev][curr] = i;
guest[i] = curr;
continue;
}
int j = bio[prev][curr];
int cycle = i - j;
int ret = j + ((k - j) % cycle);
cout << guest[ret] + 1 << endl;
return 0;
}
cout << guest[k] + 1 << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |