제출 #545472

#제출 시각아이디문제언어결과실행 시간메모리
545472rainboy우주 해적 (JOI14_space_pirate)C11
10 / 100
2090 ms2452 KiB
#include <stdio.h>
#include <string.h>

#define N	100000

int solve(int *pp, int n, long long k) {
	static int tt[N];
	int i, t;

	memset(tt, 0, n * sizeof *tt);
	i = 0, t = 0;
	while (!tt[i])
		tt[i] = t++, i = pp[i];
	k = (k - t) % (t - tt[i]);
	while (k--)
		i = pp[i];
	return i;
}

int main() {
	static int pp[N];
	static long long tt[N], ans[N];
	int n, i, j;
	long long k, t, t_;

	scanf("%d%lld", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &pp[i]), pp[i]--;
	for (i = 0, t = k; !tt[i]; i = pp[i], t--)
		tt[i] = t;
	j = i, t_ = t % (tt[i] - t);
	while (t_--)
		j = pp[j];
	for (i = 0; i < n; i++)
		if (!tt[i])
			ans[j] += n;
	for (i = 0; i < n; i++)
		if (tt[i]) {
			int p = pp[i];

			for (pp[i] = 0; pp[i] < n; pp[i]++)
				ans[solve(pp, n, k)]++;
			pp[i] = p;
		}
	for (i = 0; i < n; i++)
		printf("%lld\n", ans[i]);
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

space_pirate.c: In function 'main':
space_pirate.c:26:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  scanf("%d%lld", &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~~~
space_pirate.c:28:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |   scanf("%d", &pp[i]), pp[i]--;
      |   ^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...