이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#define N 100000
#define N_ 5000
int max(int a, int b) { return a > b ? a : b; }
int main() {
static int aa[N], bb[N], qu[N], pp[N], qq[N], dp[N_][N_];
int n, cnt, same, i, j, b, k, good;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
for (i = 0; i < n; i++)
scanf("%d", &bb[i]);
same = 1;
for (i = 1; i < n; i++)
if (bb[i] != bb[i - 1]) {
same = 0;
break;
}
if (same) {
b = bb[0], k = 0;
for (i = 0; i < n; i++)
if (aa[i] <= b) {
j = i;
good = 0;
while (j < n && aa[j] <= b)
if (aa[j++] == b)
good = 1;
if (good)
k += j - i;
i = j;
}
printf("%d\n", k);
return 0;
}
cnt = 0;
for (i = 0; i < n; i++) {
while (cnt && aa[qu[cnt - 1]] <= aa[i])
cnt--;
pp[i] = cnt ? qu[cnt - 1] : -1;
qu[cnt++] = i;
}
cnt = 0;
for (i = n - 1; i >= 0; i--) {
while (cnt && aa[qu[cnt - 1]] <= aa[i])
cnt--;
qq[i] = cnt ? qu[cnt - 1] : n;
qu[cnt++] = i;
}
if (n <= N_) {
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
dp[i][j] = max(i == 0 ? 0 : dp[i - 1][j], (j == 0 ? 0 : dp[i][j - 1]) + (aa[i] == bb[j] && pp[i] < j && j < qq[i] ? 1 : 0));
printf("%d\n", dp[n - 1][n - 1]);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
exam.c: In function 'main':
exam.c:12:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
exam.c:14:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
exam.c:16:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d", &bb[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... |