Submission #201199

#TimeUsernameProblemLanguageResultExecution timeMemory
201199OrtPolitičari (COCI20_politicari)C++11
70 / 70
26 ms1400 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; int n; ll k; int mt[505][505]; set<pair<int,int> > C; vector<int> p, R; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin >> mt[i][j]; p.push_back(1); int start = 2; int next = 0; while(true) { if(C.count(make_pair(p.back(), start))) break; C.insert(make_pair(p.back(), start)); next = mt[start][p.back()]; p.push_back(start); start = next; } int fst = 1; for(int i=0;i<p.size()-1;i++) { if(p[i+1]==next && p[i]==p.back()) break; fst++; } for(int i=fst;i<p.size();i++) R.push_back(p[i]); if(k==1) cout << 1; else if(k==2) cout << 2; else { if(k<=fst) { cout << p[k]; return 0; } k -= fst; k--; int md = R.size(); cout << R[k%md]; } return 0; }

Compilation message (stderr)

politicari.cpp: In function 'int main()':
politicari.cpp:40:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<p.size()-1;i++) {
              ~^~~~~~~~~~~
politicari.cpp:45:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=fst;i<p.size();i++) R.push_back(p[i]);
                ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...