# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
883809 | vjudge1 | Političari (COCI20_politicari) | C++17 | 13 ms | 1432 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifndef Local
#pragma GCC optimize("O3,unroll-loops")
const int lim=2e5+100;
#else
const int lim=2e3+100;
#endif
#include "bits/stdc++.h"
using namespace std;
//#define int long long
#define pb push_back
const int mod=1e9+7;
using pii=pair<int,int>;
inline void solve(){
int n,k;
cin>>n>>k;
int a[n+1][n+1];
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
}
}
if(k==1){
cout<<1;
return;
}
unordered_map<int,int>all,rev;
int now=2,past=1,time=2;
while(!all.count(now*n+past)){
if(k==time){
cout<<now<<"\n";
return;
}
all[now*n+past]=time;
rev[time]=now;
past=a[now][past];
swap(now,past);
time++;
}
int loopy=all[now*n+past];
k-=loopy;
k%=time-loopy;
k+=loopy;
cout<<rev[k]<<"\n";
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
#ifdef Local
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#else
//freopen("grass.in","r",stdin);
//freopen("grass.out","w",stdout);
#endif
int t=1;
//cin>>t;
while (t--)
{
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |