제출 #868873

#제출 시각아이디문제언어결과실행 시간메모리
868873pccPolitičari (COCI20_politicari)C++14
70 / 70
15 ms3252 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define fs first #define sc second #define tlll tuple<ll,ll,ll> const int mxn = 505; int dir[mxn][mxn]; int idx[mxn][mxn]; ll n,k; int C; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n>>k; if(k == 1){ cout<<1; return 0; } else if(k == 2){ cout<<2; return 0; } for(int i = 1;i<=n;i++){ for(int j = 1;j<=n;j++)cin>>dir[i][j]; } pii now = {2,1}; k -= 2; do{ k--; idx[now.fs][now.sc] = ++C; int nxt = dir[now.fs][now.sc]; now = {nxt,now.fs}; if(!k){ cout<<now.fs<<'\n'; return 0; } }while(!idx[now.fs][now.sc]); ll sz = C+1-idx[now.fs][now.sc]; k %= sz; memset(idx,0,sizeof(idx)); while(k){ k--; int nxt = dir[now.fs][now.sc]; now = {nxt,now.fs}; } cout<<now.fs; }
#Verdict Execution timeMemoryGrader output
Fetching results...