Submission #744449

#TimeUsernameProblemLanguageResultExecution timeMemory
744449rainboyCrazy old lady (IZhO13_crazy)C11
100 / 100
11 ms300 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...