이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define name "LIS"
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, b, a) for (int i = (b); i >= (a); i--)
template <class U, class V>
bool maximize(U &x, V y) {
if (x < y) { x = y; return true; }
return false;
}
template <class U, class V>
bool minimize(U &x, V y) {
if (x > y) { x = y; return true; }
return false;
}
const int INF = 2e9 + 7;
const int N = 3e5 + 5;
int a[N];
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
if (fopen(name".inp", "r")) {
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
int n, d;
cin >> n >> d;
FOR(i, 1, n) cin >> a[i];
vector<int> f(n + 1, 0); f[0] = INF;
vector<int> suff(n + 1, 0);
int ans = 0;
FOD(i, n, 1) {
int idx = lower_bound(f.begin(), f.end(), a[i], greater<int>()) - f.begin();
suff[i] = idx;
f[idx] = a[i];
maximize(ans, idx);
}
f = vector<int>(n + 1, INF); f[0] = 0;
FOR(i, 1, n - 1) {
int idx = lower_bound(f.begin(), f.end(), a[i]) - f.begin();
f[idx] = a[i];
idx = lower_bound(f.begin(), f.end(), a[i + 1] + d) - f.begin();
maximize(ans, idx + suff[i + 1] - 1);
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen(name".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen(name".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... |