이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int INF = 2e9 + 7;
int n, x;
int v[MAXN];
int dp[MAXN];
int maxiPos[MAXN], maxiNeg[MAXN];
int ans;
void bt(int cur, int sum);
int main(){
scanf("%d %d", &n, &x);
for(int i = 1; i <= n; i++)
scanf("%d", &v[i]);
if(x == 1e9){
for(int j = 1; j <= n; j++)
dp[j] = INF;
for(int i = 1; i <= n; i++){
int k = lower_bound(dp, dp + 1 + n, v[i]) - dp;
dp[k] = v[i];
maxiPos[i] = max(maxiPos[i - 1], k);
ans = max(ans, k);
}
for(int j = 1; j <= n; j++)
dp[j] = INF;
dp[0] = -INF;
for(int i = n; i > 0; i--){
int k = lower_bound(dp, dp + 1 + n, -v[i]) - dp;
dp[k] = -v[i];
maxiNeg[i] = max(maxiNeg[i + 1], k);
ans = max(ans, k);
ans = max(ans, maxiPos[i] + maxiNeg[i + 1]);
}
printf("%d\n", ans);
return 0;
}
if(x == 0){
for(int j = 1; j <= n; j++)
dp[j] = INF;
for(int i = 1; i <= n; i++){
int k = lower_bound(dp, dp + 1 + n, v[i]) - dp;
dp[k] = v[i];
ans = max(ans, k);
}
printf("%d\n", ans);
return 0;
}
for(int i = n; i > 0; i--){
for(int j = 1; j <= n; j++)
dp[j] = INF;
for(int j = 1; j <= n; j++){
int k = lower_bound(dp, dp + 1 + n, v[j]) - dp;
dp[k] = v[j];
ans = max(ans, k);
}
v[i] += x;
}
printf("%d\n", ans);
}
void bt(int cur, int sum){
for(int i = 1; i <= n; i++)
dp[i] = INF;
for(int i = 1; i <= n; i++){
int k = lower_bound(dp, dp + 1 + n, v[i]) - dp;
dp[k] = v[i];
ans = max(ans, k);
}
if(cur == n) return;
v[cur + 1] += sum;
bt(cur + 1, sum);
v[cur + 1] -= sum;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &x);
~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &v[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... |