Submission #3247544
Source Code Expand
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; using namespace std; /***********************************************/ /* Dear online judge: * I've read the problem, and tried to solve it. * Even if you don't accept my solution, you should respect my effort. * I hope my code compiles and gets accepted. * ___ __ _______ _______ * |\ \|\ \ |\ ___ \ |\ ___ \ * \ \ \/ /|_\ \ __/| \ \ __/| * \ \ ___ \\ \ \_|/__\ \ \_|/__ * \ \ \\ \ \\ \ \_|\ \\ \ \_|\ \ * \ \__\\ \__\\ \_______\\ \_______\ * \|__| \|__| \|_______| \|_______| */ const long double mod = 1000000007; const long long inf = 1000000000000000ll; const int mxN = 5010; long long dp[2][mxN]; long long A[mxN]; long long P[mxN]; int N,K; vector<long long> ind[mxN]; vector<long long> rmd[mxN]; vector<long long> inp[mxN]; long long get(long long mn) { long long p = 0; for(int i = N-1;i >= 0;i--) { p += A[i]; if(p >= mn) dp[1][i] = p; else dp[1][i] = inf; } for(int k = 2;k <= K;k++) { int d = k&1; int o = !d; multiset<long long> dpm; long long mnp = inf; for(int i = N-1;i >= 0;i--) { dp[d][i] = inf; while(!ind[i].empty()) { auto s = ind[i].back(); ind[i].pop_back(); dpm.insert(s); } while(!rmd[i].empty()) { auto s = rmd[i].back(); rmd[i].pop_back(); dpm.erase(dpm.find(s)); } while(!inp[i].empty()) { auto s = inp[i].back(); inp[i].pop_back(); mnp = min(mnp,s); } if(!dpm.empty()) dp[d][i] = min(dp[d][i], *dpm.begin()); if(mnp < inf) dp[d][i] = min(dp[d][i], mnp - (i?P[i-1]:0)); if(i && P[i-1] >= mn) { int at = upper_bound(P,P+i,P[i-1] - mn) - P; assert(at < i); assert(P[i-1] - (at?P[at-1]:0) >= mn); ind[at].push_back(dp[o][i]); int to = upper_bound(P,P+at+1,P[i-1] - dp[o][i]) - P; if(dp[o][i] <= P[i-1]) { assert(to <= at); assert(P[i-1] - (to?P[to-1]:0) >= dp[o][i]); rmd[to].push_back(dp[o][i]), inp[to].push_back(P[i-1]); } } } } return dp[K&1][0]; } int validate(long long mn) { int cnt = 0; for(int i = 0;i < N;) { int j = i; while(j < N && P[j] - (i?P[i-1]:0) < mn) j++; if(j != N) cnt++; i = j + 1; } return cnt; } int main(int argc, char** argv) { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; // cin>>T; T = 1; while(T--) { cin>>N; K = 4; for(int i = 0;i < N;i++) cin>>A[i], P[i] = (i?P[i-1]:0) + A[i]; long long lo = 1,hi = P[N-1],out = inf, mout = -inf; while(lo <= hi) { long long md = (lo + hi) >> 1; if(validate(md) >= K) { mout = md; lo = md + 1; } else { hi = md - 1; } } out = get(mout) - mout; cout<<out<<'\n'; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Equal Cut |
User | vjudge5 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 3018 Byte |
Status | RE |
Exec Time | 101 ms |
Memory | 768 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 600 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_28.txt, subtask_1_29.txt, subtask_1_30.txt, subtask_1_31.txt, subtask_1_32.txt, subtask_1_33.txt, subtask_1_34.txt, subtask_1_35.txt, subtask_1_36.txt, subtask_1_37.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 1 ms | 640 KB |
sample_02.txt | AC | 1 ms | 640 KB |
sample_03.txt | AC | 1 ms | 640 KB |
subtask_1_01.txt | AC | 1 ms | 640 KB |
subtask_1_02.txt | RE | 99 ms | 768 KB |
subtask_1_03.txt | RE | 99 ms | 768 KB |
subtask_1_04.txt | RE | 99 ms | 768 KB |
subtask_1_05.txt | AC | 1 ms | 640 KB |
subtask_1_06.txt | RE | 99 ms | 768 KB |
subtask_1_07.txt | RE | 98 ms | 768 KB |
subtask_1_08.txt | RE | 98 ms | 768 KB |
subtask_1_09.txt | RE | 98 ms | 768 KB |
subtask_1_10.txt | RE | 99 ms | 768 KB |
subtask_1_11.txt | RE | 99 ms | 768 KB |
subtask_1_12.txt | RE | 98 ms | 768 KB |
subtask_1_13.txt | RE | 98 ms | 768 KB |
subtask_1_14.txt | RE | 99 ms | 768 KB |
subtask_1_15.txt | RE | 98 ms | 768 KB |
subtask_1_16.txt | RE | 98 ms | 768 KB |
subtask_1_17.txt | RE | 98 ms | 768 KB |
subtask_1_18.txt | RE | 97 ms | 640 KB |
subtask_1_19.txt | RE | 98 ms | 768 KB |
subtask_1_20.txt | RE | 99 ms | 768 KB |
subtask_1_21.txt | RE | 99 ms | 768 KB |
subtask_1_22.txt | RE | 101 ms | 768 KB |
subtask_1_23.txt | RE | 99 ms | 768 KB |
subtask_1_24.txt | RE | 99 ms | 768 KB |
subtask_1_25.txt | RE | 98 ms | 768 KB |
subtask_1_26.txt | RE | 98 ms | 768 KB |
subtask_1_27.txt | RE | 98 ms | 768 KB |
subtask_1_28.txt | RE | 99 ms | 768 KB |
subtask_1_29.txt | RE | 98 ms | 768 KB |
subtask_1_30.txt | RE | 99 ms | 768 KB |
subtask_1_31.txt | RE | 99 ms | 768 KB |
subtask_1_32.txt | RE | 99 ms | 768 KB |
subtask_1_33.txt | RE | 99 ms | 768 KB |
subtask_1_34.txt | RE | 98 ms | 768 KB |
subtask_1_35.txt | RE | 98 ms | 768 KB |
subtask_1_36.txt | RE | 99 ms | 768 KB |
subtask_1_37.txt | RE | 98 ms | 768 KB |