답안 #959400

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959400 2024-04-08T07:02:36 Z Pring Bigger segments (IZhO19_segments) C++17
100 / 100
56 ms 21444 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

// #define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MXN = 500005;
int n, a[MXN];
int dp[MXN];
ll pre[MXN];
vector<pli> dq;
int ptr;

void DP(int id) {
    while (ptr < dq.size() && dq[ptr].fs <= pre[id]) ptr++;
    int l = dq[ptr - 1].sc;
    dp[id] = dp[l] + 1;
    pli now = mp(2 * pre[id] - pre[l], id);
    debug(now.fs, now.sc);
    while (dq.size() && dq.back().fs >= now.fs) dq.pop_back();
    dq.push_back(now);
}

void miku() {
    cin >> n;
    FOR(i, 1, n + 1) cin >> a[i];
    FOR(i, 1, n + 1) pre[i] = pre[i - 1] + a[i];
    dq.push_back(mp(0LL, 0));
    FOR(i, 1, n + 1) DP(i);
    cout << dp[n] << '\n';
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    miku();
    return 0;
}

Compilation message

segments.cpp: In function 'void DP(int)':
segments.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     while (ptr < dq.size() && dq[ptr].fs <= pre[id]) ptr++;
      |            ~~~~^~~~~~~~~~~
segments.cpp:11:20: warning: statement has no effect [-Wunused-value]
   11 | #define debug(...) 39
      |                    ^~
segments.cpp:35:5: note: in expansion of macro 'debug'
   35 |     debug(now.fs, now.sc);
      |     ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2508 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2508 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 0 ms 460 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 348 KB Output is correct
30 Correct 1 ms 2408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2508 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 0 ms 460 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 348 KB Output is correct
30 Correct 1 ms 2408 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 508 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 496 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2508 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 0 ms 460 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 348 KB Output is correct
30 Correct 1 ms 2408 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 508 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 496 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 8 ms 4312 KB Output is correct
47 Correct 9 ms 4464 KB Output is correct
48 Correct 11 ms 2904 KB Output is correct
49 Correct 11 ms 3804 KB Output is correct
50 Correct 12 ms 5080 KB Output is correct
51 Correct 11 ms 6616 KB Output is correct
52 Correct 7 ms 2724 KB Output is correct
53 Correct 4 ms 1760 KB Output is correct
54 Correct 7 ms 4312 KB Output is correct
55 Correct 12 ms 5080 KB Output is correct
56 Correct 8 ms 4568 KB Output is correct
57 Correct 10 ms 4312 KB Output is correct
58 Correct 8 ms 4384 KB Output is correct
59 Correct 9 ms 4568 KB Output is correct
60 Correct 9 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2508 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 0 ms 460 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 348 KB Output is correct
30 Correct 1 ms 2408 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 508 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 496 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 8 ms 4312 KB Output is correct
47 Correct 9 ms 4464 KB Output is correct
48 Correct 11 ms 2904 KB Output is correct
49 Correct 11 ms 3804 KB Output is correct
50 Correct 12 ms 5080 KB Output is correct
51 Correct 11 ms 6616 KB Output is correct
52 Correct 7 ms 2724 KB Output is correct
53 Correct 4 ms 1760 KB Output is correct
54 Correct 7 ms 4312 KB Output is correct
55 Correct 12 ms 5080 KB Output is correct
56 Correct 8 ms 4568 KB Output is correct
57 Correct 10 ms 4312 KB Output is correct
58 Correct 8 ms 4384 KB Output is correct
59 Correct 9 ms 4568 KB Output is correct
60 Correct 9 ms 4444 KB Output is correct
61 Correct 40 ms 17964 KB Output is correct
62 Correct 39 ms 18336 KB Output is correct
63 Correct 39 ms 18788 KB Output is correct
64 Correct 54 ms 14832 KB Output is correct
65 Correct 54 ms 21400 KB Output is correct
66 Correct 56 ms 21416 KB Output is correct
67 Correct 44 ms 19288 KB Output is correct
68 Correct 26 ms 11568 KB Output is correct
69 Correct 45 ms 17508 KB Output is correct
70 Correct 50 ms 21444 KB Output is correct
71 Correct 38 ms 18404 KB Output is correct
72 Correct 44 ms 18928 KB Output is correct
73 Correct 45 ms 19576 KB Output is correct
74 Correct 44 ms 19908 KB Output is correct
75 Correct 42 ms 19688 KB Output is correct