#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 time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Incorrect |
11 ms |
760 KB |
Output isn't correct |
3 |
Incorrect |
16 ms |
1636 KB |
Output isn't correct |
4 |
Incorrect |
21 ms |
1916 KB |
Output isn't correct |
5 |
Incorrect |
25 ms |
2296 KB |
Output isn't correct |
6 |
Incorrect |
23 ms |
2296 KB |
Output isn't correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Incorrect |
6 ms |
504 KB |
Output isn't correct |
9 |
Incorrect |
10 ms |
888 KB |
Output isn't correct |
10 |
Incorrect |
20 ms |
1912 KB |
Output isn't correct |
11 |
Incorrect |
24 ms |
2424 KB |
Output isn't correct |
12 |
Incorrect |
22 ms |
2296 KB |
Output isn't correct |
13 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
14 |
Incorrect |
6 ms |
504 KB |
Output isn't correct |