이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define file "input"
void setIO(string name="") {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(file".in", "r")) {
freopen(file".in", "r", stdin);
freopen(file".out", "w", stdout);
}
}
const int N = 2e5+5;
int n, x, a[N], dp[2][N];
int main() {
setIO();
cin >> n >> x;
foru(i, 1, n) cin >> a[i];
a[n+1] = (int)1e9+1;
foru(r, 0, 1) {
vector<int> lis;
foru(i, 1, n) {
int it = lower_bound(all(lis), a[i]) - lis.begin();
if (r) dp[r][i] = it+1;
if (it == lis.size()) lis.push_back(a[i]);
else lis[it] = a[i];
if (!r) dp[r][i] = lower_bound(all(lis), a[i+1]+x) - lis.begin();
}
reverse(a+1, a+n+1);
}
int ans = 0;
foru(i, 1, n) ans = max(ans, dp[0][i] + dp[1][n-i]);
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:38:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | if (it == lis.size()) lis.push_back(a[i]);
| ~~~^~~~~~~~~~~~~
glo.cpp: In function 'void setIO(std::string)':
glo.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | freopen(file".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | freopen(file".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |