답안 #492419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492419 2021-12-07T08:01:37 Z TAMREF K개의 묶음 (IZhO14_blocks) C++17
100 / 100
228 ms 4084 KB
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define pp push_back
#define ep emplace_back
#define all(v) (v).begin(),(v).end()
#define szz(v) ((int)(v).size())
#define bi_pc __builtin_popcount
#define bi_pcll __builtin_popcountll
#define bi_tz __builtin_ctz
#define bi_tzll __builtin_ctzll
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef TAMREF
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 42
#endif
using namespace std;
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cerr << vars << " = ";
    string delim = "";
    (..., (cerr << delim << values, delim = ", "));
    cerr << '\n';
}
#ifdef TAMREF
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
#else
#define deb(...) 42
#endif
using ll = long long; using lf = long double; 
using pii = pair<int,int>; using ppi = pair<int,pii>;
using pll = pair<ll,ll>; using pff = pair<lf,lf>;
using ti = tuple<int,int,int>;
using base = complex<double>;
const lf PI = 3.14159265358979323846264338L;
template <typename T>
inline T umax(T& u, T v){return u = max(u, v);}
template <typename T>
inline T umin(T& u, T v){return u = min(u, v);}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mx = 1e5 + 5;
int n, k;
int a[mx];
vector<int> dp, tp;

int main(){
    fio;
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];
    tp = vector<int>(n + 1, 2000000);
    tp[0] = 0;
    for(int j = 1; j <= k; j++) {
        dp = vector<int>(n + 1);
        vector<ti> stk;
        vector<pii> dtk;
        for(int i = j-1; i >= 1; i--) tp[i-1] = min(tp[i-1], tp[j]);
        for(int i = j; i <= n; i++) {
            int tpm = tp[i-1];
            while(szz(stk) && get<0>(stk.back()) <= a[i]) {
                tpm = min(tpm, get<1>(stk.back()));
                stk.pop_back();
            }   
            while(szz(dtk) && a[dtk.back().vb] < a[i]) dtk.pop_back();

            if(dtk.empty() || tpm + a[i] < dtk.back().va + a[dtk.back().vb]) dtk.ep(tpm, i);
            dp[i] = dtk.back().va + a[dtk.back().vb];
            stk.ep(a[i], tpm, i);
        }
        deb(j);
        for(int i : dp) debug("%d ", i); debug("\n");
        tp = dp;
    }
    cout << dp[n] << '\n';
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:32:18: warning: statement has no effect [-Wunused-value]
   32 | #define deb(...) 42
      |                  ^~
blocks.cpp:74:9: note: in expansion of macro 'deb'
   74 |         deb(j);
      |         ^~~
blocks.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
blocks.cpp:75:25: note: in expansion of macro 'debug'
   75 |         for(int i : dp) debug("%d ", i); debug("\n");
      |                         ^~~~~
blocks.cpp:75:17: warning: unused variable 'i' [-Wunused-variable]
   75 |         for(int i : dp) debug("%d ", i); debug("\n");
      |                 ^
blocks.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
blocks.cpp:75:42: note: in expansion of macro 'debug'
   75 |         for(int i : dp) debug("%d ", i); debug("\n");
      |                                          ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 1 ms 320 KB Output is correct
52 Correct 0 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 0 ms 204 KB Output is correct
56 Correct 0 ms 204 KB Output is correct
57 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 1 ms 320 KB Output is correct
52 Correct 0 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 0 ms 204 KB Output is correct
56 Correct 0 ms 204 KB Output is correct
57 Correct 0 ms 204 KB Output is correct
58 Correct 5 ms 588 KB Output is correct
59 Correct 4 ms 1100 KB Output is correct
60 Correct 9 ms 1308 KB Output is correct
61 Correct 53 ms 1464 KB Output is correct
62 Correct 180 ms 2876 KB Output is correct
63 Correct 21 ms 2508 KB Output is correct
64 Correct 80 ms 2572 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Correct 1 ms 320 KB Output is correct
67 Correct 1 ms 320 KB Output is correct
68 Correct 0 ms 204 KB Output is correct
69 Correct 1 ms 272 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 19 ms 460 KB Output is correct
72 Correct 2 ms 460 KB Output is correct
73 Correct 6 ms 460 KB Output is correct
74 Correct 5 ms 1072 KB Output is correct
75 Correct 9 ms 1308 KB Output is correct
76 Correct 69 ms 1448 KB Output is correct
77 Correct 197 ms 2940 KB Output is correct
78 Correct 14 ms 2564 KB Output is correct
79 Correct 95 ms 2508 KB Output is correct
80 Correct 11 ms 2124 KB Output is correct
81 Correct 30 ms 2876 KB Output is correct
82 Correct 198 ms 2868 KB Output is correct
83 Correct 1 ms 332 KB Output is correct
84 Correct 1 ms 332 KB Output is correct
85 Correct 18 ms 692 KB Output is correct
86 Correct 2 ms 588 KB Output is correct
87 Correct 6 ms 700 KB Output is correct
88 Correct 8 ms 1420 KB Output is correct
89 Correct 10 ms 1832 KB Output is correct
90 Correct 71 ms 1872 KB Output is correct
91 Correct 228 ms 4084 KB Output is correct
92 Correct 16 ms 3904 KB Output is correct
93 Correct 107 ms 4076 KB Output is correct
94 Correct 2 ms 460 KB Output is correct
95 Correct 17 ms 544 KB Output is correct
96 Correct 1 ms 332 KB Output is correct
97 Correct 0 ms 332 KB Output is correct
98 Correct 1 ms 204 KB Output is correct
99 Correct 0 ms 204 KB Output is correct