# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
341316 | A_D | Političari (COCI20_politicari) | C++14 | 58 ms | 4332 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.
/*
ID: antwand1
TASK: pprime
LANG: C++
*/
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define du long double
#define F first
#define S second
#define FOR(a,b) for(int a=1;a<=b;a++)
#define FORl(a,b) for(a=1;a<=b;a++)
#define FOR0(a,b) for(int a=1;a<b;a++)
#define FORl0(a,b) for(a=0;a<b;a++)
using namespace std;
const int N=501;
int a[N][N];
int vis[N][N];
vector<int> vec;
vector<int> v;
main()
{
//freopen("pprime.in","r",stdin);freopen("pprime.out","w",stdout);
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
}
}
vec.push_back(1);
vec.push_back(2);
int x=2,y=1;
int cnt=2,cur=0;
while(1){
// cout<<x<<" "<<y<<endl;
if(vis[x][y]){
cur=vis[x][y];
break;
}
vis[x][y]=cnt++;
vec.push_back(a[x][y]);
int Y=x;
int X=a[x][y];
x=X;
y=Y;
}
// cout<<"\n\n";
//cout<<cur<<"\n\n";
for(int i=0;i<cur;i++){
k--;
if(!k){
cout<<vec[i];
return 0;
}
}
for(int i=cur;i<vec.size();i++){
v.push_back(vec[i]);
}
int sz=v.size();
// cout<<"\n\n\n";
//for(int i=0;i<vec.size();i++)cout<<vec[i]<<" ";
// cout<<"\n\n\n";
// for(int i=0;i<v.size();i++)cout<<v[i]<<" ";
//cout<<"\n\n\n\n";
k--;
k%=sz;
cout<<v[k]<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |