#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define int long long
using namespace std;
const int N=1e6,M=2e3,mod=1e9+7;
int a[1000][1000];
map<pair<int,int>,int>viss;
vector<pair<int,int>>v;
pair<int,int>anss;
main()
{
v.clear();
anss={0,0};
viss.clear();
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
v.pb({0,1});
v.pb({1,2});
viss[{0,1}]=1;
viss[{1,2}]=1;
while(1){
int x=v.size()-1;
if(viss[{v[x].S,a[v[x].S-1][v[x].F-1]}]==1){
anss.F=v[x].S;
anss.S=a[v[x].S-1][v[x].F-1];
break;
}
viss[{v[x].S,a[v[x].S-1][v[x].F-1]}]=1;
v.pb({v[x].S,a[v[x].S-1][v[x].F-1]});
}
assert(v.size()>20);
reverse(v.begin(),v.end());
while((v.size())&&((*v.rbegin()).F!=anss.F||(*v.rbegin()).S!=anss.S)&&m>0)
v.pop_back(),m--;
int ok=0;
for(int i=0;i<v.size();i++)
if(v[i].S==51)
ok=1;
assert(ok!=1);
reverse(v.begin(),v.end());
int xx=m%v.size();
if(xx==0)
xx=v.size();
xx--;
// assert(v[xx].S>12);
cout<<v[xx].S<<endl;
return 0;
}
Compilation message
politicari.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
12 | main()
| ^~~~
politicari.cpp: In function 'int main()':
politicari.cpp:55:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 6 |
2 |
Correct |
14 ms |
1524 KB |
Output is correct |
3 |
Correct |
42 ms |
3100 KB |
Output is correct |
4 |
Correct |
55 ms |
3616 KB |
Output is correct |
5 |
Correct |
61 ms |
4176 KB |
Output is correct |
6 |
Correct |
48 ms |
4172 KB |
Output is correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
8 |
Runtime error |
8 ms |
1748 KB |
Execution killed with signal 6 |
9 |
Runtime error |
13 ms |
3252 KB |
Execution killed with signal 6 |
10 |
Correct |
51 ms |
3596 KB |
Output is correct |
11 |
Runtime error |
72 ms |
8336 KB |
Execution killed with signal 6 |
12 |
Runtime error |
66 ms |
8372 KB |
Execution killed with signal 6 |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
980 KB |
Output is correct |