結果
問題 | No.448 ゆきこーだーの雨と雪 (3) |
ユーザー | femto |
提出日時 | 2016-11-18 23:24:42 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,747 bytes |
コンパイル時間 | 1,533 ms |
コンパイル使用メモリ | 169,444 KB |
実行使用メモリ | 16,324 KB |
最終ジャッジ日時 | 2023-08-17 12:07:51 |
合計ジャッジ時間 | 5,200 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
9,504 KB |
testcase_01 | AC | 2 ms
9,508 KB |
testcase_02 | AC | 2 ms
9,512 KB |
testcase_03 | AC | 3 ms
9,500 KB |
testcase_04 | AC | 3 ms
9,716 KB |
testcase_05 | AC | 3 ms
9,568 KB |
testcase_06 | AC | 2 ms
9,600 KB |
testcase_07 | AC | 3 ms
9,520 KB |
testcase_08 | WA | - |
testcase_09 | AC | 3 ms
9,520 KB |
testcase_10 | AC | 3 ms
9,604 KB |
testcase_11 | AC | 3 ms
9,528 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
コンパイルメッセージ
main.cpp: メンバ関数 ‘void MaxSegTree::init(int)’ 内: main.cpp:15:34: 警告: overflow in conversion from ‘long long int’ to ‘int’ changes value from ‘-1125899906842624’ to ‘0’ [-Woverflow] 15 | dat[i] = -INF; | ^~~~ main.cpp: メンバ関数 ‘int MaxSegTree::query(int, int, int, int, int)’ 内: main.cpp:33:45: 警告: overflow in conversion from ‘long long int’ to ‘int’ changes value from ‘-1125899906842624’ to ‘0’ [-Woverflow] 33 | if(r <= a || b <= l) return -INF; | ^~~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX_N = 1 << 20; const ll INF = 1LL << 50; typedef pair<ll, ll> P; class MaxSegTree { int n, dat[2 * MAX_N - 1]; public: void init(int n_) { n = 1; while(n < n_) n *= 2; for(int i = 0; i < 2 * n - 1; i++) { dat[i] = -INF; } } void update(int k, int a) { k += n - 1; dat[k] = a; while(k > 0) { k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]); } } int query(int a, int b) { return query(a, b, 0, 0, n); } int query(int a, int b, int k, int l, int r) { if(r <= a || b <= l) return -INF; if(a <= l && r <= b) return dat[k]; else { int vl = query(a, b, k * 2 + 1, l, (l + r) / 2); int vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } } void show() { for(int i = 0; i < n; i++) { cout << dat[i + n - 1] << " "; } cout << endl; } }; ll T[200010]; ll D[200010]; int nxt[200010]; ll S[200010]; P dp[200010]; MaxSegTree seg; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; seg.init(N); for(int i = 0; i < N; i++) { cin >> T[i] >> D[i]; seg.update(i, D[i]); } T[N] = 1e9 + 10; for(int i = 0; i < N; i++) { S[i + 1] = S[i] + D[i]; nxt[i] = lower_bound(T, T + N + 1, T[i] + K) - T; } for(int i = 0; i < N + 1; i++) { dp[i] = P(INF, INF); } dp[0] = P(0, 0); for(int i = 0; i < N; i++) { { P p = dp[i]; p.first = max(p.first, D[i]); p.second += D[i]; dp[i + 1] = min(dp[i + 1], p); } { P p = dp[i]; p.first = max(p.first, (ll)seg.query(i + 1, nxt[i])); p.second += S[nxt[i]] - S[i + 1]; dp[nxt[i]] = min(dp[nxt[i]], p); } } cout << dp[N].first << endl; cout << dp[N].second << endl; }