제출 #1288615

#제출 시각아이디문제언어결과실행 시간메모리
1288615samarthkulkarniDischarging (NOI20_discharging)C++20
36 / 100
1099 ms55260 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; // #pragma GCC target ("avx2") // #pragma GCC optimize ("O3") // #pragma GCC optimize ("unroll-loops") // #pragma GCC optimize("fast-math") #define ll long long #define ld long double #define vi vector<ll> #define endl "\n" #define pr pair<ll, ll> #define ff first #define ss second #define all(x) x.begin(), x.end() const int mod = 1e9+7; void _p(ll a){cout<<a<<endl;} void _p(string a){cout<<a<<endl;} void _p(ld a) {cout<<a<<endl;} template <class T> void _p(vector<T> a){for(T val:a)cout<<val<<" ";cout<<endl;} #define debug(x) cout<<#x<<" -> ";_p(x) typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > ordered_set; vector<pr> move8 = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; vector<pr> move4 = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; vector<pr> move2 = {{0, 1}, {1, 0}}; void solution(); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solution(); return 0; } struct SegTree { vi a, tree; ll n; SegTree(const vi& temp) { a = temp; n = a.size()-1; tree.resize(4*n); } void build(ll id, ll l, ll r) { if (l == r) { tree[id] = a[l]; return; } ll mid = (l + r)/2; build(2*id, l, mid); build(2*id+1, mid+1, r); tree[id] = max(tree[2*id], tree[2*id+1]); } ll query(ll id, ll l, ll r, ll L, ll R) { if (L > r || l > R) return 0; if (L <= l && R >= r) return tree[id]; ll mid = (l + r)/2; return max(query(2*id, l, mid, L, R), query(2*id+1, mid+1, r, L, R)); } void build() {build(1, 1, n);} ll query(ll l, ll r) {return query(1, 1, n, l, r);} }; void solution() { ll n; cin >> n; vi a(n+1); for (int i = 1; i <= n; i++) cin >> a[i]; SegTree M(a); M.build(); vi dp(n+1, 1e18); dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < i; j++) { dp[i] = min(dp[i], dp[j] + M.query(j+1, i)*(n-j)); } } cout << dp[n] << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...