제출 #337246

#제출 시각아이디문제언어결과실행 시간메모리
337246boykutBigger segments (IZhO19_segments)C++14
13 / 100
1 ms364 KiB
#include <bits/stdc++.h>

using namespace std;

#define MAXN 500001
#define fr first
#define sc second

int a[MAXN], dp[MAXN];
int prefsum[MAXN], sm[MAXN];

int main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   
   int n;
   cin >> n;
   
   for (int i = 1; i <= n; i++) {
      cin >> a[i];
      prefsum[i] = prefsum[i - 1] + a[i];
   }
   
   auto get = [&] (int left, int right) -> long long {
      return prefsum[right] - prefsum[left - 1];
   };
   
   priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
   q.push({0, 0});
   
   int tmp = 0;
   for (int i = 1; i <= n; i++) {
      while (!q.empty() && q.top().fr <= prefsum[i]) {
         if (dp[q.top().sc] > dp[tmp]) {
            tmp = q.top().sc;
         } else if (dp[q.top().sc] == dp[tmp]) {
            tmp = max(tmp, q.top().sc);
         }
         q.pop();
      }
      q.push({prefsum[i] * 2 - prefsum[tmp], i});
		dp[i] = dp[tmp] + 1;
   }
   
   cout << dp[n] << '\n';
   
   return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

segments.cpp: In function 'int main()':
segments.cpp:24:9: warning: variable 'get' set but not used [-Wunused-but-set-variable]
   24 |    auto get = [&] (int left, int right) -> long long {
      |         ^~~
#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...