답안 #175927

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
175927 2020-01-07T12:23:27 Z mcdx9524 Bigger segments (IZhO19_segments) C++14
37 / 100
1500 ms 3064 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int rand(int l, int r) {
    return uniform_int_distribution <int> (l, r) (rnd);
}

const int inf = 1e9 + 7;

void solve() {
    int n;
    cin >> n;
    vector <int> a(n + 1, 0);
    vector <ll> pref(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        pref[i] = a[i] + pref[i - 1];
    }
    vector <pair <int, ll> > dp(n + 1, {0, inf});
    dp[0] = {0, 0};
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < i; j++) {
            ll sum = pref[i] - pref[j];
            if (sum >= dp[j].second) {
                if (dp[j].first + 1 > dp[i].first) {
                    dp[i].first = dp[j].first + 1;
                    dp[i].second = sum;
                } else if (dp[j].first + 1 == dp[i].first) {
                    dp[i].second = min(dp[i].second, sum);
                }
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (dp[i].first < dp[i - 1].first) {
            assert(0);
        }
    }
    cout << dp[n].first << '\n';
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int test_cnt = 1;
    //cin >> test_cnt;
    while (test_cnt--) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 252 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 252 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 12 ms 348 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 252 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 12 ms 348 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 6 ms 376 KB Output is correct
32 Correct 14 ms 376 KB Output is correct
33 Correct 13 ms 468 KB Output is correct
34 Correct 9 ms 504 KB Output is correct
35 Correct 9 ms 376 KB Output is correct
36 Correct 14 ms 376 KB Output is correct
37 Correct 10 ms 376 KB Output is correct
38 Correct 7 ms 376 KB Output is correct
39 Correct 14 ms 420 KB Output is correct
40 Correct 14 ms 376 KB Output is correct
41 Correct 9 ms 376 KB Output is correct
42 Correct 9 ms 376 KB Output is correct
43 Correct 13 ms 508 KB Output is correct
44 Correct 9 ms 376 KB Output is correct
45 Correct 10 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 252 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 12 ms 348 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 6 ms 376 KB Output is correct
32 Correct 14 ms 376 KB Output is correct
33 Correct 13 ms 468 KB Output is correct
34 Correct 9 ms 504 KB Output is correct
35 Correct 9 ms 376 KB Output is correct
36 Correct 14 ms 376 KB Output is correct
37 Correct 10 ms 376 KB Output is correct
38 Correct 7 ms 376 KB Output is correct
39 Correct 14 ms 420 KB Output is correct
40 Correct 14 ms 376 KB Output is correct
41 Correct 9 ms 376 KB Output is correct
42 Correct 9 ms 376 KB Output is correct
43 Correct 13 ms 508 KB Output is correct
44 Correct 9 ms 376 KB Output is correct
45 Correct 10 ms 504 KB Output is correct
46 Execution timed out 1551 ms 3064 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 252 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 12 ms 348 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 6 ms 376 KB Output is correct
32 Correct 14 ms 376 KB Output is correct
33 Correct 13 ms 468 KB Output is correct
34 Correct 9 ms 504 KB Output is correct
35 Correct 9 ms 376 KB Output is correct
36 Correct 14 ms 376 KB Output is correct
37 Correct 10 ms 376 KB Output is correct
38 Correct 7 ms 376 KB Output is correct
39 Correct 14 ms 420 KB Output is correct
40 Correct 14 ms 376 KB Output is correct
41 Correct 9 ms 376 KB Output is correct
42 Correct 9 ms 376 KB Output is correct
43 Correct 13 ms 508 KB Output is correct
44 Correct 9 ms 376 KB Output is correct
45 Correct 10 ms 504 KB Output is correct
46 Execution timed out 1551 ms 3064 KB Time limit exceeded
47 Halted 0 ms 0 KB -