제출 #1006399

#제출 시각아이디문제언어결과실행 시간메모리
1006399devariaotaBigger segments (IZhO19_segments)C++17
100 / 100
63 ms18852 KiB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[500005], pos[500005], pref[500005], a[500005];
int main()
{
  ll n;
  scanf("%lld", &n);
  for(int i=1; i<=n; i++)
  {
    scanf("%lld", &a[i]);
    pref[i]=pref[i-1]+a[i];
  }
  pref[n+1]=1e18;
  for(int i=1; i<=n; i++)
  {
    pos[i]=max(pos[i], pos[i-1]);
    dp[i]=dp[pos[i]]+1;
    ll pt=lower_bound(pref+1, pref+n+1, 2*pref[i]-pref[pos[i]])-pref;
//    printf("pos=%lld %lld %lld\n", pos[i], pt, dp[i]);
    pos[pt]=i;
  }
  printf("%lld\n", dp[n]);
}

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

segments.cpp: In function 'int main()':
segments.cpp:8:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   scanf("%lld", &n);
      |   ~~~~~^~~~~~~~~~~~
segments.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%lld", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~~~
#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...