답안 #957822

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957822 2024-04-04T11:12:49 Z I_am_Polish_Girl Bigger segments (IZhO19_segments) C++14
100 / 100
187 ms 29568 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <cmath>
#include <random>
#include <chrono>

using namespace std;

#define int long long

int log_ = 10;
int inf = 1000000000000000000;
int mod = 998244353;




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

    int n;
    cin >> n;

    vector <int> a(n);
    vector <int> pref(n);

    vector <int> dp(n);
    vector <int> col(n);

    int pr = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];

        pr += a[i];

        pref[i] = pr;

        dp[i] = pref[i];
        col[i] = 1;
    }

    pref.push_back(inf);


    vector <int> syf(n , -1);
    vector <int> syf_col(n  , 1);

    int ans = 0;
    for (int i = 0; i < n; i++)
    {

        int x = pref[i];


        if (i > 0)
        {

            if (syf[i - 1] == syf[i])
                syf_col[i] = max(syf_col[i - 1], syf_col[i]);

            if (syf[i - 1] > syf[i])
            {
                syf[i] = syf[i - 1];
                syf_col[i] = syf_col[i - 1];
            }
        }

        if (syf[i] != -1)
            dp[i] = pref[i] - pref[syf[i]];
        else
            dp[i] = pref[i];

        col[i] = syf_col[i];

        ans = max(ans, col[i]);

        int ind = lower_bound(pref.begin(), pref.end(), x + dp[i]) - pref.begin();

        if (ind == n)
            continue;

        syf[ind] = i;
        syf_col[ind] = col[i]+1;
    }

    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 500 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 500 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 500 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 768 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 344 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 356 KB Output is correct
44 Correct 1 ms 756 KB Output is correct
45 Correct 1 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 500 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 768 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 344 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 356 KB Output is correct
44 Correct 1 ms 756 KB Output is correct
45 Correct 1 ms 356 KB Output is correct
46 Correct 17 ms 5460 KB Output is correct
47 Correct 28 ms 5452 KB Output is correct
48 Correct 29 ms 5964 KB Output is correct
49 Correct 34 ms 5980 KB Output is correct
50 Correct 42 ms 6564 KB Output is correct
51 Correct 33 ms 6228 KB Output is correct
52 Correct 21 ms 3016 KB Output is correct
53 Correct 11 ms 1904 KB Output is correct
54 Correct 17 ms 5196 KB Output is correct
55 Correct 46 ms 6092 KB Output is correct
56 Correct 24 ms 5468 KB Output is correct
57 Correct 29 ms 5512 KB Output is correct
58 Correct 28 ms 5700 KB Output is correct
59 Correct 29 ms 5676 KB Output is correct
60 Correct 25 ms 5700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 500 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 768 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 344 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 356 KB Output is correct
44 Correct 1 ms 756 KB Output is correct
45 Correct 1 ms 356 KB Output is correct
46 Correct 17 ms 5460 KB Output is correct
47 Correct 28 ms 5452 KB Output is correct
48 Correct 29 ms 5964 KB Output is correct
49 Correct 34 ms 5980 KB Output is correct
50 Correct 42 ms 6564 KB Output is correct
51 Correct 33 ms 6228 KB Output is correct
52 Correct 21 ms 3016 KB Output is correct
53 Correct 11 ms 1904 KB Output is correct
54 Correct 17 ms 5196 KB Output is correct
55 Correct 46 ms 6092 KB Output is correct
56 Correct 24 ms 5468 KB Output is correct
57 Correct 29 ms 5512 KB Output is correct
58 Correct 28 ms 5700 KB Output is correct
59 Correct 29 ms 5676 KB Output is correct
60 Correct 25 ms 5700 KB Output is correct
61 Correct 87 ms 27480 KB Output is correct
62 Correct 96 ms 26080 KB Output is correct
63 Correct 119 ms 26228 KB Output is correct
64 Correct 162 ms 28264 KB Output is correct
65 Correct 163 ms 29516 KB Output is correct
66 Correct 162 ms 28664 KB Output is correct
67 Correct 151 ms 22548 KB Output is correct
68 Correct 67 ms 12804 KB Output is correct
69 Correct 92 ms 25196 KB Output is correct
70 Correct 187 ms 29568 KB Output is correct
71 Correct 119 ms 27404 KB Output is correct
72 Correct 104 ms 26728 KB Output is correct
73 Correct 118 ms 27932 KB Output is correct
74 Correct 134 ms 27920 KB Output is correct
75 Correct 133 ms 26908 KB Output is correct