Submission #201329

#TimeUsernameProblemLanguageResultExecution timeMemory
201329kayuPolitičari (COCI20_politicari)C++14
10 / 70
25 ms2424 KiB
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589; #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define pb push_back #define mp make_pair #define int long long #define all(c) (c).begin(),(c).end() #define M 1000000007 #define INF LLONG_MAX #define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__) template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";} template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);} template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";} template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";} template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";} template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";} template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";} // Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n) // int32_t main() { fastio; //freopen("file.in", "r", stdin); //freopen("file.out", "w", stdout); int n, k; cin >> n >> k; vector<vector<int>> v(n, vector<int>(n)); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cin >> v[i][j]; } } int curr = 2, last_used = 1, period = 0; map<pair<int, int>, bool> found; map<int, int> z; while(found.find({curr, last_used}) == found.end()) { found[{curr, last_used}] = true; period++; z[period] = last_used; int temp = curr; curr = v[curr-1][last_used-1]; last_used = temp; } k %= period; if(k == 0) k = period; cout << z[k] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...