제출 #911019

#제출 시각아이디문제언어결과실행 시간메모리
911019daoquanglinh2007Bigger segments (IZhO19_segments)C++17
0 / 100
2 ms344 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair <int, int> #define fi first #define se second #define mp make_pair #define isz(a) (int)(a).size() const int NM = 5e5; int N, a[NM+5], pref[NM+5], trace[NM+5]; pii dp[NM+5]; vector <int> v; void add(int x){ while (!v.empty() && pref[v.back()]+dp[v.back()].se >= pref[x]+dp[x].se) v.pop_back(); v.push_back(x); } signed main(){ freopen("SEGMENTS.inp", "r", stdin); freopen("SEGMENTS.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for (int i = 1; i <= N; i++){ cin >> a[i]; pref[i] = pref[i-1]+a[i]; } add(0); for (int i = 1; i <= N; i++){ int l = 0, r = isz(v)-1; while (l <= r){ int mid = (l+r)/2; if (pref[i] >= pref[v[mid]]+dp[v[mid]].se){ dp[i].fi = dp[v[mid]].fi+1; dp[i].se = pref[i]-pref[v[mid]]; l = mid+1; } else r = mid-1; } add(i); } cout << dp[N].fi; return 0; }

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

segments.cpp: In function 'int main()':
segments.cpp:23:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  freopen("SEGMENTS.inp", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:24:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  freopen("SEGMENTS.out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...