# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
863425 | vjudge1 | Političari (COCI20_politicari) | C++17 | 16 ms | 5368 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.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long
using namespace std;
typedef tuple<int, int, int> iii;
typedef long long ll;
const int mod =998244353;
int n, k;
int a[505][505], vis[505][505];
vector<int> v, vv;
int mOd(int x, int y){
if(x%y)return x%y;
else return y;
}
int32_t main(){
fast;
cin>>n>>k;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
}
}
if(k==1){
cout<<1<<endl;
return 0;
}
else k--;
int i=2, j=1, ind=0, cnt;
while(true){
if(vis[i][j]){
//~ cout<<i<<" :: "<<j<<endl;
for(int k=vis[i][j];k<=(int)v.size()-1;k++){
vv.pb(v[k]);
}
cnt=vis[i][j];
break;
}
vis[i][j]=ind;
v.pb(i);
ind++;
int t=i;
i=a[i][j];
j=t;
}
//~ cout<<v.size()<<" :: "<<vv.size()<<" :: "<<cnt<<endl;
//~ for(auto it: v){
//~ cout<<it<<" v ";
//~ }
//~ cout<<endl;
//~ for(auto it: vv){
//~ cout<<it<<" vv ";
//~ }
//~ cout<<endl;
if(k<=cnt){
cout<<v[k-1]<<endl;
}
else{
k-=cnt;
cout<<vv[mOd(k, (int)vv.size())-1]<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |