제출 #957146

#제출 시각아이디문제언어결과실행 시간메모리
957146RequiemBigger segments (IZhO19_segments)C++17
37 / 100
1552 ms3420 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second #define f1(i,n) for(int i=1;i<=n;i++) #define f0(i,n) for(int i=0;i<=n;i++) #define add(a,b) a=(a+b)%MOD #define BIT(mask,i) ((mask >> i) & 1ll ) #define OFF(mask,i) (mask & (~(1ll << i))) #define ON(mask,i) (mask | (1ll << i)) #define xd '\n' #define DAO(mask,i) (mask ^ (1ll << i)) #define add(a,b) a=(a+b)%MOD #define built(mask) __builtin_popcountll(mask) #define all(x) x.begin(),x.end() #define XD cout << '\n' #define TASK "task" //dqxzzz using namespace std; const int oo = 1e18; const int maxn = 1e5+5; const int MOD = 1e9+7; int a[maxn]; pair<int,int> dp[maxn]; int f[maxn]; int n; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen(TASK".inp","r",stdin); // freopen(TASK".out","w",stdout); cin >> n; f1(i,n) cin >> a[i]; f1(i,n) f[i]=f[i-1]+a[i]; dp[1] = {1,a[1]}; f1(i,n) { f0(j,i-1) { if (f[i] - f[j] >= dp[j].se) { if (dp[j].fi + 1 > dp[i].fi) { dp[i].fi = dp[j].fi + 1; dp[i].se = f[i]-f[j]; } else if (dp[j].fi + 1 == dp[i].fi && f[i]-f[j] < dp[i].se) { dp[i].fi = dp[j].fi + 1; dp[i].se = f[i]-f[j]; } } } } cout << dp[n].fi; return 0; }
#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...