제출 #1166402

#제출 시각아이디문제언어결과실행 시간메모리
1166402DangKhoizzzzBigger segments (IZhO19_segments)C++20
13 / 100
0 ms328 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second #define pii pair <int , int> #define arr3 array <int , 3> /* + array limit ??? + special case ??? n = 1? + time limit ??? */ using namespace std; const int INF = 1e18 + 7; const int maxn = 5e5 + 7; int n , a[maxn] , pre[maxn]; pii dp[maxn]; namespace small_subtask { // checkk if small sub full int ans = 0; void solve() { for(int i = 1; i <= n; i++) { for(int j = 0; j <= i-1; j++) { if((pre[i] - pre[j]) >= dp[j].se) { if(dp[i].fi < dp[j].fi + 1) { dp[i].fi = dp[j].fi + 1; dp[i].se = pre[i] - pre[j]; } else if(dp[i].fi == dp[j].fi + 1) { dp[i].se = min(dp[i].se , pre[i] - pre[j]); } } } ans = max(ans , dp[i].fi); } cout << ans << '\n'; } } namespace full_subtask { int ans = 0ll; void solve() { priority_queue <arr3 , vector <arr3> , greater <arr3>> PQ; arr3 cur = {0 , 0 , 0}; PQ.push({0 , 0 , 0}); for(int i = 1; i <= n; i++) { while(!PQ.empty() && PQ.top()[0] <= pre[i]) { cur = max(cur , {PQ.top()[2] , PQ.top()[0] , PQ.top()[1]}); PQ.pop(); } dp[i].fi = cur[0] + 1; dp[i].se = pre[i] + -cur[2]; PQ.push({dp[i].se + pre[i] , pre[i] , dp[i].fi}); ans = max(ans , dp[i].fi); } cout << ans << '\n'; } } void read_solve() { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) { pre[i] = pre[i-1] + a[i]; } full_subtask::solve(); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen("inp.txt" , "r" , stdin); //freopen("out.txt" , "w" , stdout); read_solve(); 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...