제출 #1289041

#제출 시각아이디문제언어결과실행 시간메모리
1289041BahaminBigger segments (IZhO19_segments)C++20
100 / 100
155 ms45300 KiB
#include <bits/stdc++.h> using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } #define ll long long #define ld long double #define all(a) (a).begin(), (a).end() #define lid chs[id].first #define rid chs[id].second #define mid ((r + l) >> 1) #define sui cout.tie(NULL); cin.tie(NULL); ios_base::sync_with_stdio(false) const int MAX_N = 5e5 + 5; const int MOD = 1e9 + 7; const ll INF = 1e18; const ld EPS = 1e-9; const int LOG = 60; void solve() { int n; cin >> n; int a[n]; ll ps[n + 1]; pair<int, ll> dp[n + 1]; for (int i = 0; i < n; i++) cin >> a[i], ps[i + 1] = ps[i] + a[i]; int ans = 0; set<pair<ll, int>> al; for (int i = 0; i < n; i++) { while (al.size() && (*al.begin()).first <= ps[i + 1]) { int ind = (*al.begin()).second; al.erase(al.begin()); ans = max(ans, ind); } dp[i + 1] = {dp[ans].first + 1, ps[i + 1] - ps[ans]}; al.insert({ps[i + 1] + dp[i + 1].second, i + 1}); } cout << dp[n].first << "\n"; } int main() { sui; int tc = 1; //cin >> tc; for (int t = 1; t <= tc; t++) { solve(); } }
#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...