이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;
#define fur(i, a, b) for(ll i = a; i <= (ll) b; ++i)
#define ruf(i, a, b) for(ll i = a; i >= (ll) b; --i)
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define nl "\n"
const ll mxn = 1e4L + 1;
#warning mxn is according to subtask
ll n, s, k;
ll d[mxn];
ll v[mxn];
ll x[mxn];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> s >> k;
fur(i, 1, n - 1) {
cin >> d[i];
}
fur(i, 1, n) {
cin >> v[i];
}
x[1] = 0;
fur(i, 2, n) {
x[i] = x[i - 1] + d[i - 1];
}
ll sum[n + 1];
sum[0] = 0;
fur(i, 1, n) {
sum[i] = sum[i - 1] + v[i];
}
ll res = 0;
ll dp[n + 1][s + 1] = {};
ll frst[n + 1][s + 1] = {};
ll prev[n + 1] = {};
fur(i, 1, n) {
frst[i][1] = i;
}
fur(j, 2, s) {
fur(i, 1, n) {
ll pr = lower_bound(x + 1, x + n + 1, x[i] - k) - x - 1;
pr = lower_bound(x + 1, x + n + 1, x[pr] - k) - x;
frst[i][j] = frst[pr][j - 1];
prev[i] = pr;
}
}
ll right = 0, num = 0;
fur(i, 1, n) {
fur(j, 1, s) {
ll l = frst[i][j];
ll lt = lower_bound(x + 1, x + n + 1, x[l] - k) - x - 1;
ll rt = upper_bound(x + 1, x + n + 1, x[i] + k) - x - 1;
dp[i][j] = sum[rt] - sum[lt];
if(dp[i][j] > res) {
res = dp[i][j];
right = i; num = j;
}
}
}
vl ans;
while(num--) {
ans.eb(right);
right = prev[right];
}
reverse(all(ans));
cout << ans.size() << nl;
for(auto u : ans)
cout << u << ' ';
cout << nl;
}
컴파일 시 표준 에러 (stderr) 메시지
SolarStorm.cpp:24:2: warning: #warning mxn is according to subtask [-Wcpp]
24 | #warning mxn is according to subtask
| ^~~~~~~
# | 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... |