이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<cstdio>
#include<climits>
#include<algorithm>
using namespace std;
#define MAXN 200000
#define MAXK 1000000000
#define MAXNUM 1000000000
int A[MAXN], INC[MAXN], DEC[MAXN];
int main() {
int K, N;
scanf("%d %d\n", &N, &K);
for (int i=0; i<N; i++) scanf("%d", &(A[i]));
INC[0]=1;
for (int i=1; i<N; i++) {
INC[i] = 1;
for (int j=i-1; j>=0; j--)
if (A[i] > A[j]) INC[i] = max(INC[i], 1+INC[j]);
}
DEC[N-1]=1;
for (int i=N-2; i>=0; i--) {
DEC[i] = 1;
for (int j=i+1; j<N; j++)
if (A[i] < A[j]) DEC[i] = max(DEC[i], 1+DEC[j]);
}
/*for (int i=1; i<N; i++) { INC[i] = max(INC[i], INC[i-1]); printf("%d ", INC[i]); }
printf("\n");
for (int i=N-2; i>=0; i--) { DEC[i] = max(DEC[i], DEC[i+1]); printf("%d ", DEC[i]); }
printf("\n");*/
int res = 0;
for (int i=0; i<N; i++) res = max(res, INC[i]);
if (K == 0) {
printf("%d\n", res);
return 0;
}
for (int i=0; i<N-1; i++) {
for (int j=i+1; j<N; j++)
if (A[i] - A[j] < K) {
res = max(res, INC[i]+DEC[j]);
//printf("%d (%d, %d): %d (%d, %d)\n", i, A[i], A[i+1], res, INC[i], DEC[i+1]);
}
}
printf("%d\n", res);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d %d\n", &N, &K);
| ~~~~~^~~~~~~~~~~~~~~~~~~
glo.cpp:17:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | for (int i=0; i<N; i++) scanf("%d", &(A[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... |