Submission #545466

# Submission time Handle Problem Language Result Execution time Memory
545466 2022-04-04T14:49:16 Z rainboy Space Pirate (JOI14_space_pirate) C
10 / 100
2000 ms 2388 KB
#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 ans[N];
	int n, i;
	long long k;

	scanf("%d%lld", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &pp[i]), pp[i]--;
	for (i = 0; i < n; 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;
}

Compilation message

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 time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 2 ms 292 KB Output is correct
7 Correct 3 ms 212 KB Output is correct
8 Correct 2 ms 260 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 2 ms 296 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 2 ms 292 KB Output is correct
7 Correct 3 ms 212 KB Output is correct
8 Correct 2 ms 260 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 2 ms 296 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Execution timed out 2083 ms 340 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2070 ms 2388 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 2 ms 292 KB Output is correct
7 Correct 3 ms 212 KB Output is correct
8 Correct 2 ms 260 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 2 ms 296 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Execution timed out 2083 ms 340 KB Time limit exceeded
16 Halted 0 ms 0 KB -