Submission #744449

# Submission time Handle Problem Language Result Execution time Memory
744449 2023-05-18T14:58:01 Z rainboy Crazy old lady (IZhO13_crazy) C
100 / 100
11 ms 300 KB
#include <stdio.h>
#include <string.h>

#define N	1000

int main() {
	int t;

	scanf("%d", &t);
	while (t--) {
		static int pp[N];
		static char used[N];
		int n, i, i_, j, good, tmp;

		scanf("%d", &n);
		for (i = 0; i < n; i++)
			scanf("%d", &pp[i]), pp[i]--;
		i_ = -1;
		for (i = 0; i < n; i++) {
			memset(used, 0, n * sizeof *used), used[pp[i]] = 1;
			good = 1;
			for (j = 0; j < n; j++) {
				if (j == i)
					continue;
				if (!used[j] && pp[j] != j) {
					good = 0;
					break;
				}
				used[pp[j]] = 1;
			}
			if (good) {
				if (i_ == -1)
					i_ = i;
				else {
					i_ = -1;
					break;
				}
			}
			if (i + 1 < n)
				tmp = pp[i], pp[i] = pp[i + 1], pp[i + 1] = tmp;
		}
		printf("%d\n", i_ + 1);
	}
	return 0;
}

Compilation message

crazy.c: In function 'main':
crazy.c:9:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  scanf("%d", &t);
      |  ^~~~~~~~~~~~~~~
crazy.c:15:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   scanf("%d", &n);
      |   ^~~~~~~~~~~~~~~
crazy.c:17:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |    scanf("%d", &pp[i]), pp[i]--;
      |    ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 296 KB Output is correct
11 Correct 3 ms 300 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 3 ms 300 KB Output is correct
15 Correct 6 ms 212 KB Output is correct
16 Correct 6 ms 300 KB Output is correct
17 Correct 7 ms 212 KB Output is correct
18 Correct 10 ms 212 KB Output is correct
19 Correct 8 ms 212 KB Output is correct
20 Correct 11 ms 212 KB Output is correct