이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#define N 1000000
#define INF 0x3f3f3f3f
#define MD 1000003
int min(int a, int b) { return a < b ? a : b; }
int main() {
static int aa[N];
int n, i, l, r, a, k, bll, blr, brr, brl, ans;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
ans = 0;
for (a = 1; ; a++) {
l = 0;
while (l < n && aa[l] <= a)
l++;
if (l == n)
break;
r = n - 1;
while (r >= 0 && aa[r] <= a)
r--;
k = 0;
for (i = l; i <= r; i++)
if (aa[i] <= a)
k++;
if (k > 0) {
ans = (ans + (long long) (a * 3 + 2) * k) % MD;
bll = blr = INF;
for (i = l; i <= r; i++)
if (aa[i] > a)
bll = min(bll, aa[i]);
else {
while (i <= r) {
if (aa[i] > a)
blr = min(blr, aa[i]);
i++;
}
break;
}
brr = brl = INF;
for (i = r; i >= l; i--)
if (aa[i] > a)
brr = min(brr, aa[i]);
else {
while (i >= l) {
if (aa[i] > a)
brl = min(brl, aa[i]);
i--;
}
break;
}
if (k == 1)
ans = (ans + bll + brr - (a + 1) * 2) % MD;
else
ans = (ans + bll + brr + min(blr, brl) - (a + 1) * 3) % MD;
}
}
printf("%d\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.c: In function 'main':
Main.c:13:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
Main.c:15:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |