제출 #497715

#제출 시각아이디문제언어결과실행 시간메모리
497715vinnipuh01Bigger segments (IZhO19_segments)C++17
0 / 100
1 ms204 KiB
#include <iostream> #include <bits/stdc++.h> #include <cmath> #include <algorithm> #include <vector> #include <deque> #include <set> #include <stack> #include <string> #include <map> #include <queue> #define int long long using namespace std; const long long oo = 1000000000000000000; long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos; /* ViHHiPuh (( `'-""``""-'` )) )-__-_.._-__-( / --- (o _ o) --- \ \ .-* ( .0. ) *-. / _'-. ,_ '=' _, .-'_ / `;#'#'# - #'#'#;` \ \_)) -----'#'----- ((_/ # --------- # '# ------- ------ #' /..-'# ------- #'-.\ _\...-\'# -- #'/-.../_ ((____)- '#' -(____)) cout << fixed << setprecision(6) << x; freopen ( "sum.in", "r", stdin ) */ pair<int, int> dp[ 500001 ]; int p[ 500001 ]; main () { int n; cin >> n; int a[ n + 1 ]; for ( int i = 1; i <= n; i ++ ) { cin >> a[ i ]; p[ i ] = p[ i - 1 ] + a[ i ]; } int l, r, mid; for ( int i = 1; i <= n; i ++ ) { dp[i].second = max(dp[i].second, dp[i -1].second); l = i; r = n; while ( r > l ) { mid = ( l + r ) / 2; if ( p[ mid ] >= 2 * p[ i ] - p[ dp[ i ].second ] ) r = mid; else l = mid + 1; } dp[ l ] = max( dp[ l ], { dp[ i ].first + 1, i } ); } cout << dp[ n ].first; } // p[mid] - p[ i - 1 ] >= p[ i - 1 ] - p[ dp[ i - 1 ].second ]

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

segments.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main () {
      | ^~~~
#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...