結果

問題 No.2488 Mod Sum Maximization
ユーザー milanis48663220
提出日時 2023-09-29 22:19:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 907 ms / 2,000 ms
コード長 2,084 bytes
コンパイル時間 1,130 ms
コンパイル使用メモリ 120,376 KB
最終ジャッジ日時 2025-02-17 03:21:49
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0