#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[510][510];
map<pair<int,int>,int>vis;
main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
vector<pair<int,int>>v;
v.pb({0,1});
v.pb({1,2});
vis[{0,1}]=1;
vis[{1,2}]=1;
pair<int,int>ans;
while(1){
int x=v.size()-1;
if(vis[{v[x].S,a[v[x].S-1][v[x].F-1]}]==1){
ans.F=v[x].S;
ans.S=a[v[x].S-1][v[x].F-1];
break;
}
vis[{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]});
}
reverse(v.begin(),v.end());
pair<int,int> lst={-1,-1};
while(((*v.rbegin()).F!=ans.F||(*v.rbegin()).S!=ans.S)&&m>0){
lst=*v.rbegin();
v.pop_back(),m--;
}
if(m==0){
cout<<lst.F<<" "<<lst.S<<endl;
return 0;
}
reverse(v.begin(),v.end());
int xx=m%v.size();
if(xx==0)
xx=v.size(),xx--;
cout<<v[xx].S<<endl;
return 0;
}
Compilation message
politicari.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
11 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
10 ms |
1192 KB |
Output isn't correct |
3 |
Incorrect |
32 ms |
1908 KB |
Output isn't correct |
4 |
Incorrect |
40 ms |
2084 KB |
Output isn't correct |
5 |
Incorrect |
63 ms |
2264 KB |
Output isn't correct |
6 |
Incorrect |
57 ms |
2228 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
852 KB |
Output isn't correct |
9 |
Incorrect |
13 ms |
1268 KB |
Output isn't correct |
10 |
Incorrect |
38 ms |
2048 KB |
Output isn't correct |
11 |
Incorrect |
49 ms |
2296 KB |
Output isn't correct |
12 |
Correct |
53 ms |
2268 KB |
Output is correct |
13 |
Incorrect |
1 ms |
444 KB |
Output isn't correct |
14 |
Incorrect |
6 ms |
852 KB |
Output isn't correct |