QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#250231 | #4590. Happy Travelling | warner1129 | WA | 18ms | 4636kb | C++20 | 2.9kb | 2023-11-12 23:29:57 | 2023-11-12 23:29:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template<class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
template<class T> void org(T l, T r) { while (l != r) cerr << ' ' << *l++; cerr << '\n'; }
#define debug(x...) dbg(#x, '=', x, '\n')
#define olist(x...) dbg(#x, '='), org(x)
#else
#define debug(...) ((void)0)
#define olist(...) ((void)0)
#endif
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
template<class T>
inline constexpr T inf = numeric_limits<T>::max() / 2;
constexpr int mod = 998244353;
template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }
template<class... T> int add(T... x) { int t{}; return (((t += x) %= mod), ...), t; }
template<class... T> int mul(T... x) { i64 t{1}; return (((t *= x) %= mod), ...), t; }
void solve() {
int n, K, D;
cin >> n >> K >> D;
vector<int> H(n);
vector<int> T(n - 1);
for (int &x : H) cin >> x;
for (int &x : T) cin >> x;
if (K * K <= 1e5) {
vector<vector<int>> stk(K);
vector<i64> dp(n, -inf<i64>);
dp[n - 1] = H[n - 1];
stk[(n - 1) % K].push_back(n - 1);
for (int i = n - 2; i >= 0; i--) {
for (int j = 0; j < K; j++) {
auto it = lower_bound(all(stk[j]), i + T[i], greater<int>{});
if (it != stk[j].end()) {
chmax(dp[i], dp[*it] - (*it - i) / K * D + H[i]);
}
}
int s = i % K;
while (!stk[s].empty() and dp[stk[s].back()] - stk[s].back() / K < dp[i] - i / K) {
stk[s].pop_back();
}
stk[s].push_back(i);
}
cout << dp[0] << '\n';
} else {
const int lgK = __lg(K);
vector st(lgK + 1, vector<i64>(n, -inf<i64>));
vector<i64> dp(n);
dp[n - 1] = H[n - 1];
auto upd = [&](int idx) -> void {
st[0][idx] = dp[idx];
for (int i = 0; i + 1 <= lgK and idx + (2 << i) <= n; i++) {
st[i + 1][idx] = max(st[i][idx], st[i][idx + (1 << i)]);
}
};
auto qry = [&](int l, int r) -> i64 {
int s = __lg(r - l);
return max(st[s][l], st[s][r - (1 << s)]);
};
upd(n - 1);
for (int i = n - 2; i >= 0; i--) {
for (int j = i; j <= i + T[i]; j += K) {
chmax(dp[i], qry(max(j, i + 1), min(j + K, i + T[i] + 1)) - (j - i) / K * D + H[i]);
}
upd(i);
}
cout << dp[0] << '\n';
}
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3432kb
input:
6 2 1 8 -7 -8 9 0 2 5 3 3 2 1
output:
18
result:
ok single line: '18'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3428kb
input:
8 8 8 10 -5 -5 -5 -5 -5 -5 10 5 2 5 3 2 1 1
output:
15
result:
ok single line: '15'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3432kb
input:
13 2 2 -5 -4 -4 -1 7 -6 -5 -4 -3 -2 -1 5 -7 3 10 9 8 7 6 5 4 3 2 1 1
output:
-9
result:
ok single line: '-9'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
2 1 0 -10000 10000 1
output:
0
result:
ok single line: '0'
Test #5:
score: -100
Wrong Answer
time: 18ms
memory: 4636kb
input:
98987 4 3 -8225 -8961 -5537 -5621 -8143 -5214 -5538 -6912 -6601 -8839 -7872 -7867 -9553 -9793 -7333 -7360 -5820 -7459 -8824 -9716 -9757 -5846 -5300 -5912 -7953 -8360 -7609 -5937 -5525 -9748 -7326 -8311 -9979 -9292 -8542 -7589 -7939 -5914 -7985 -9999 -9212 -8274 -8084 -6620 -5991 -7826 -6327 -5228 -6...
output:
-84131
result:
wrong answer 1st lines differ - expected: '-84108', found: '-84131'