| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 868873 | pcc | Političari (COCI20_politicari) | C++14 | 15 ms | 3252 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>
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 time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
