# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
550651 | rainboy | 빌딩 장식 3 (JOI15_building3) | C11 | 119 ms | 11952 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |