Submission #201013

#TimeUsernameProblemLanguageResultExecution timeMemory
201013dolphingarlicPolitičari (COCI20_politicari)C++14
70 / 70
25 ms1656 KiB
#include <bits/stdc++.h> #define FOR(i, x, y) for (int i = x; i < y; i++) typedef long long ll; using namespace std; int a[501][501], nxt[501][501]; bool visited[501][501]; vector<int> tail, cycle; int main() { iostream::sync_with_stdio(false); cin.tie(0); int n; ll m; cin >> n >> m; FOR(i, 1, n + 1) FOR(j, 1, n + 1) cin >> a[i][j]; pair<int, int> curr = {1, 2}; while (true) { if (visited[curr.second][curr.first]) { pair<int, int> here = {1, 2}; tail.push_back(1); while (here != curr) { tail.push_back(here.second); here = {here.second, a[here.second][here.first]}; } cycle.push_back(here.second); here = {here.second, a[here.second][here.first]}; while (here != curr) { cycle.push_back(here.second); here = {here.second, a[here.second][here.first]}; } break; } else { visited[curr.second][curr.first] = true; curr = {curr.second, a[curr.second][curr.first]}; } } if (m <= tail.size()) cout << tail[m - 1]; else cout << cycle[(m - tail.size() - 1) % cycle.size()]; return 0; }

Compilation message (stderr)

politicari.cpp: In function 'int main()':
politicari.cpp:41:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (m <= tail.size()) cout << tail[m - 1];
         ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...