답안 #531444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531444 2022-02-28T17:08:31 Z mat50013 Bigger segments (IZhO19_segments) C++11
100 / 100
79 ms 16932 KB
#include <bits/stdc++.h>

using namespace std;
/*
    Am un sir de n numere.
    Trebuie sa-l part in cat mai multe subsecvente astfel inca sumaSubsecv[i] <= sumaSubsecv[i + 1]
    6 2 3 9 13
*/
using ll = long long;
const int NMAX(500005);
int v[NMAX], dp[NMAX];
ll sum[NMAX], bestSol[NMAX];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    int n;
    cin >> n;

    for(int i = 1; i <= n; ++i){
        cin >> v[i];
        sum[i] = sum[i - 1] + v[i];
        dp[i] = 1;
        bestSol[i] = sum[i];
    }

    for(int i = 1; i <= n; ++i){
        if(dp[i - 1] > dp[i]){
            dp[i] = dp[i - 1];
            bestSol[i] = bestSol[i - 1] + v[i];
        }
        else if(dp[i - 1] == dp[i])
            bestSol[i] = min(bestSol[i], bestSol[i - 1] + v[i]);
        int nxtPz = lower_bound(sum + i + 1, sum + n + 1, sum[i] + bestSol[i]) - sum;
        if(nxtPz <= n){
            if(dp[i] + 1 > dp[nxtPz]){
                dp[nxtPz] = dp[i] + 1;
                bestSol[nxtPz] = sum[nxtPz] - sum[i];
            }
            else if(dp[i] + 1 == dp[nxtPz])
                bestSol[nxtPz] = min(bestSol[nxtPz], sum[nxtPz] - sum[i]);
        }
    }

    cout << dp[n] << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 316 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 316 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 316 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 10 ms 3020 KB Output is correct
47 Correct 13 ms 3120 KB Output is correct
48 Correct 14 ms 3436 KB Output is correct
49 Correct 19 ms 3484 KB Output is correct
50 Correct 20 ms 3628 KB Output is correct
51 Correct 16 ms 3524 KB Output is correct
52 Correct 12 ms 1996 KB Output is correct
53 Correct 7 ms 1348 KB Output is correct
54 Correct 12 ms 2792 KB Output is correct
55 Correct 18 ms 3540 KB Output is correct
56 Correct 10 ms 3140 KB Output is correct
57 Correct 11 ms 3012 KB Output is correct
58 Correct 11 ms 3152 KB Output is correct
59 Correct 11 ms 3200 KB Output is correct
60 Correct 11 ms 3180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 316 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 10 ms 3020 KB Output is correct
47 Correct 13 ms 3120 KB Output is correct
48 Correct 14 ms 3436 KB Output is correct
49 Correct 19 ms 3484 KB Output is correct
50 Correct 20 ms 3628 KB Output is correct
51 Correct 16 ms 3524 KB Output is correct
52 Correct 12 ms 1996 KB Output is correct
53 Correct 7 ms 1348 KB Output is correct
54 Correct 12 ms 2792 KB Output is correct
55 Correct 18 ms 3540 KB Output is correct
56 Correct 10 ms 3140 KB Output is correct
57 Correct 11 ms 3012 KB Output is correct
58 Correct 11 ms 3152 KB Output is correct
59 Correct 11 ms 3200 KB Output is correct
60 Correct 11 ms 3180 KB Output is correct
61 Correct 50 ms 13896 KB Output is correct
62 Correct 56 ms 14020 KB Output is correct
63 Correct 62 ms 14384 KB Output is correct
64 Correct 72 ms 16588 KB Output is correct
65 Correct 68 ms 16932 KB Output is correct
66 Correct 79 ms 16876 KB Output is correct
67 Correct 66 ms 13508 KB Output is correct
68 Correct 45 ms 6880 KB Output is correct
69 Correct 52 ms 13088 KB Output is correct
70 Correct 70 ms 16928 KB Output is correct
71 Correct 54 ms 13976 KB Output is correct
72 Correct 54 ms 14320 KB Output is correct
73 Correct 69 ms 14916 KB Output is correct
74 Correct 64 ms 15292 KB Output is correct
75 Correct 56 ms 15232 KB Output is correct