답안 #350008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
350008 2021-01-18T20:52:48 Z arnold518 Političari (COCI20_politicari) C++14
70 / 70
31 ms 4076 KB
#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

politicari.cpp: In function 'int main()':
politicari.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |  scanf("%d%lld", &N, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
politicari.cpp:32:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |    scanf("%d", &A[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 1260 KB Output is correct
3 Correct 20 ms 2828 KB Output is correct
4 Correct 29 ms 3436 KB Output is correct
5 Correct 30 ms 3948 KB Output is correct
6 Correct 31 ms 3820 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 3 ms 748 KB Output is correct
9 Correct 7 ms 1388 KB Output is correct
10 Correct 25 ms 3308 KB Output is correct
11 Correct 31 ms 4076 KB Output is correct
12 Correct 31 ms 4076 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 4 ms 748 KB Output is correct