# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
583600 | AGE | Političari (COCI20_politicari) | C++14 | 50 ms | 1628 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;
const int N=1e6,M=2e3,mod=1e9+7;
int a[510][510];
map<pair<int,int>,int>vis;
vector<pair<int,int>>v;
pair<int,int>ans;
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];
v.pb({0,1});
v.pb({1,2});
vis[{0,1}]=1;
vis[{1,2}]=1;
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());
while((v.size())&&((*v.rbegin()).F!=ans.F||(*v.rbegin()).S!=ans.S)&&m>0)
v.pop_back(),m--;
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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |