답안 #308803

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308803 2020-10-02T00:34:14 Z nikatamliani Bigger segments (IZhO19_segments) C++14
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#define f first
#define s second 
#define ll long long 
using namespace std;
const int N = 5e5 + 10;
pair < int, ll > dp[N];
ll sum[N], n;
int main() {
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> sum[i], sum[i] += sum[i - 1];
    for(int i = 1; i <= n; ++i) {
        int l = 1, r = i, ans = 1;
        while(r >= l) {
            int m = l + r >> 1;
            if(sum[i] - sum[m - 1] >= dp[m - 1].s || dp[m - 1].f < dp[i - 1].f) {
                l = m + 1;
                ans = m;
            } else {
                r = m - 1; 
            }
        }
        dp[i].f = dp[ans - 1].f + 1;
        dp[i].s = sum[i] - sum[ans - 1];
        // for(int j = 0; j < i; ++j) {
        //     if(sum[i] - sum[j] >= dp[j].s) {
        //         if(dp[i].f == dp[j].f + 1) {
        //             dp[i].s = min(dp[i].s, sum[i] - sum[j]);
        //         } 
        //         if(dp[i].f < dp[j].f + 1) {
        //             dp[i].s = sum[i] - sum[j];
        //             dp[i].f = dp[j].f + 1;
        //         }
        //     }
        // }
    }
    cout << dp[n].f << '\n';
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:15:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   15 |             int m = l + r >> 1;
      |                     ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Incorrect 0 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Incorrect 0 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Incorrect 0 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Incorrect 0 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Incorrect 0 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -