Submission #550651

#TimeUsernameProblemLanguageResultExecution timeMemory
550651rainboy빌딩 장식 3 (JOI15_building3)C11
100 / 100
119 ms11952 KiB
#include <stdio.h> #define N 1000000 int main() { static int aa[N]; static char used[N + 1]; int n, h, i, j, a; long long ans; scanf("%d", &n); for (i = 0; i < n - 1; i++) scanf("%d", &aa[i]); used[0] = 1; a = 0; for (i = 0; i < n - 1; i++) { if (!used[aa[i] - 1]) { if (a == 0) a = aa[i]; else if (a != aa[i]) { printf("0\n"); return 0; } } used[aa[i]] = 1; } if (a == 0) { ans = 1, a = 0; for (i = 0; i < n - 1; i++) { if (a + 1 == aa[i]) a++; ans += a; } printf("%lld\n", ans); return 0; } for (j = 0; j < n - 1; j++) if (aa[j] == a) break; if (a == 2) i = -1; else for (i = 0; i < n - 1; i++) if (aa[i] == a - 2) break; if (i > j) { printf("0\n"); return 0; } ans = 0; for (h = i; h < j; h++) if (h < 0 || aa[h] != a - 1) ans++; printf("%lld\n", ans); return 0; }

Compilation message (stderr)

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