結果
問題 | No.2488 Mod Sum Maximization |
ユーザー | milanis48663220 |
提出日時 | 2023-09-29 22:19:19 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 857 ms / 2,000 ms |
コード長 | 2,084 bytes |
コンパイル時間 | 1,073 ms |
コンパイル使用メモリ | 122,112 KB |
実行使用メモリ | 14,752 KB |
最終ジャッジ日時 | 2023-09-29 22:19:34 |
合計ジャッジ時間 | 14,914 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 611 ms
14,680 KB |
testcase_04 | AC | 574 ms
14,736 KB |
testcase_05 | AC | 581 ms
14,708 KB |
testcase_06 | AC | 565 ms
14,400 KB |
testcase_07 | AC | 369 ms
9,536 KB |
testcase_08 | AC | 550 ms
14,752 KB |
testcase_09 | AC | 423 ms
9,880 KB |
testcase_10 | AC | 303 ms
9,076 KB |
testcase_11 | AC | 13 ms
4,376 KB |
testcase_12 | AC | 275 ms
8,728 KB |
testcase_13 | AC | 222 ms
6,380 KB |
testcase_14 | AC | 46 ms
4,380 KB |
testcase_15 | AC | 335 ms
9,304 KB |
testcase_16 | AC | 15 ms
4,376 KB |
testcase_17 | AC | 95 ms
4,644 KB |
testcase_18 | AC | 26 ms
4,376 KB |
testcase_19 | AC | 470 ms
9,752 KB |
testcase_20 | AC | 546 ms
14,416 KB |
testcase_21 | AC | 525 ms
10,068 KB |
testcase_22 | AC | 581 ms
14,388 KB |
testcase_23 | AC | 624 ms
14,628 KB |
testcase_24 | AC | 200 ms
6,444 KB |
testcase_25 | AC | 10 ms
4,380 KB |
testcase_26 | AC | 22 ms
4,380 KB |
testcase_27 | AC | 459 ms
9,000 KB |
testcase_28 | AC | 513 ms
9,096 KB |
testcase_29 | AC | 429 ms
8,700 KB |
testcase_30 | AC | 281 ms
6,160 KB |
testcase_31 | AC | 45 ms
4,376 KB |
testcase_32 | AC | 822 ms
9,748 KB |
testcase_33 | AC | 3 ms
4,380 KB |
testcase_34 | AC | 857 ms
14,356 KB |
testcase_35 | AC | 223 ms
6,200 KB |
testcase_36 | AC | 2 ms
4,376 KB |
testcase_37 | AC | 1 ms
4,376 KB |
testcase_38 | AC | 2 ms
4,376 KB |
testcase_39 | AC | 1 ms
4,376 KB |
testcase_40 | AC | 2 ms
4,376 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <atcoder/segtree> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } const ll inf = 1e18; ll e(){ return inf; } ll op(ll x, ll y){ return min(x, y); } using Seg = atcoder::segtree<ll, op, e>; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i]; Seg dp(n); dp.set(n-1, 0); for(int i = n-2; i >= 0; i--){ ll ans = e(); for(int x = 1; x*a[i] <= a.back(); x++){ auto pl = lower_bound(a.begin(), a.end(), x*a[i]); auto pr = lower_bound(a.begin(), a.end(), (x+1)*a[i]); int l = pl-a.begin(); int r = pr-a.begin(); ll cur = dp.prod(l, r) + x*a[i]; chmin(ans, cur); } dp.set(i, ans); } ll sum = accumulate(a.begin(), a.end(), 0ll); ll ans = sum-dp.get(0); cout << ans << endl; }