답안 #959404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959404 2024-04-08T07:05:22 Z Pring Bigger segments (IZhO19_segments) C++17
100 / 100
54 ms 18284 KB
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx2","popcnt","sse4","abm")
#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:33: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]
   33 |     while (ptr < dq.size() && dq[ptr].fs <= pre[id]) ptr++;
      |            ~~~~^~~~~~~~~~~
segments.cpp:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 39
      |                    ^~
segments.cpp:37:5: note: in expansion of macro 'debug'
   37 |     debug(now.fs, now.sc);
      |     ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2512 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2512 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2508 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2512 KB Output is correct
24 Correct 2 ms 2508 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2512 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2508 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2512 KB Output is correct
24 Correct 2 ms 2508 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2524 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 1 ms 2648 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 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 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2512 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2508 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2512 KB Output is correct
24 Correct 2 ms 2508 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2524 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 1 ms 2648 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 8 ms 7124 KB Output is correct
47 Correct 9 ms 7316 KB Output is correct
48 Correct 9 ms 5212 KB Output is correct
49 Correct 10 ms 6108 KB Output is correct
50 Correct 15 ms 7008 KB Output is correct
51 Correct 11 ms 7124 KB Output is correct
52 Correct 7 ms 5852 KB Output is correct
53 Correct 4 ms 5460 KB Output is correct
54 Correct 8 ms 7128 KB Output is correct
55 Correct 11 ms 7128 KB Output is correct
56 Correct 9 ms 7124 KB Output is correct
57 Correct 9 ms 7124 KB Output is correct
58 Correct 8 ms 7128 KB Output is correct
59 Correct 9 ms 7128 KB Output is correct
60 Correct 10 ms 7128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2512 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2508 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2512 KB Output is correct
24 Correct 2 ms 2508 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2524 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 1 ms 2648 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 8 ms 7124 KB Output is correct
47 Correct 9 ms 7316 KB Output is correct
48 Correct 9 ms 5212 KB Output is correct
49 Correct 10 ms 6108 KB Output is correct
50 Correct 15 ms 7008 KB Output is correct
51 Correct 11 ms 7124 KB Output is correct
52 Correct 7 ms 5852 KB Output is correct
53 Correct 4 ms 5460 KB Output is correct
54 Correct 8 ms 7128 KB Output is correct
55 Correct 11 ms 7128 KB Output is correct
56 Correct 9 ms 7124 KB Output is correct
57 Correct 9 ms 7124 KB Output is correct
58 Correct 8 ms 7128 KB Output is correct
59 Correct 9 ms 7128 KB Output is correct
60 Correct 10 ms 7128 KB Output is correct
61 Correct 41 ms 16708 KB Output is correct
62 Correct 40 ms 16580 KB Output is correct
63 Correct 37 ms 17876 KB Output is correct
64 Correct 46 ms 10452 KB Output is correct
65 Correct 54 ms 16448 KB Output is correct
66 Correct 53 ms 16580 KB Output is correct
67 Correct 43 ms 16072 KB Output is correct
68 Correct 22 ms 10452 KB Output is correct
69 Correct 39 ms 17172 KB Output is correct
70 Correct 49 ms 17556 KB Output is correct
71 Correct 33 ms 16604 KB Output is correct
72 Correct 35 ms 17988 KB Output is correct
73 Correct 39 ms 16584 KB Output is correct
74 Correct 40 ms 18284 KB Output is correct
75 Correct 40 ms 17392 KB Output is correct