# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
350008 | arnold518 | Političari (COCI20_politicari) | C++14 | 31 ms | 4076 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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 500;
const ll MAXK = 1e18;
int N;
ll K;
int A[MAXN+10][MAXN+10];
int P[MAXN*MAXN+10];
int vis[MAXN*MAXN+10];
int f(int x)
{
int ret=x%N;
if(ret==0) ret+=N;
return ret;
}
int main()
{
scanf("%d%lld", &N, &K);
for(int i=1; i<=N; i++)
{
for(int j=1; j<=N; j++)
{
scanf("%d", &A[i][j]);
int u=N*(j-1)+i;
int v=N*(i-1)+A[i][j];
P[u]=v;
}
}
if(K==1) return !printf("1\n");
int now=2;
for(int i=2; i<K; i++)
{
if(vis[now])
{
int cyc=i-vis[now];
while(1)
{
if(vis[now]%cyc==K%cyc) return !printf("%d\n", f(now));
now=P[now];
}
return 0;
}
else
{
vis[now]=i;
now=P[now];
}
}
printf("%d\n", f(now));
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |