답안 #492413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492413 2021-12-07T07:09:22 Z TAMREF K개의 묶음 (IZhO14_blocks) C++17
0 / 100
1 ms 204 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<pii> atk, dtk;
        atk.ep(2e6, j-1);
        dtk.ep(tp[j-1], j-1);
        auto pop = [&]() {
            if(szz(dtk) && atk.back().vb == dtk.back().vb) dtk.pop_back();
            atk.pop_back();
        };
        for(int i = j; i <= n; i++) {
            while(szz(atk) && atk.back().va < a[i]) {
                pop();
            }
            if(atk.back().vb <= dtk.back().vb) {
                dtk.back().va = tp[dtk.back().vb] + a[i];
                if(szz(dtk) > 1 && dtk.back().va >= dtk[szz(dtk) - 2].va) dtk.pop_back();
            }
            dp[i] = dtk.back().va;
            atk.ep(a[i], i);
            dtk.ep(tp[i], 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:78:9: note: in expansion of macro 'deb'
   78 |         deb(j);
      |         ^~~
blocks.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
blocks.cpp:79:25: note: in expansion of macro 'debug'
   79 |         for(int i : dp) debug("%d ", i); debug("\n");
      |                         ^~~~~
blocks.cpp:79:17: warning: unused variable 'i' [-Wunused-variable]
   79 |         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:79:42: note: in expansion of macro 'debug'
   79 |         for(int i : dp) debug("%d ", i); debug("\n");
      |                                          ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 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 1 ms 204 KB Output is correct
10 Correct 1 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 Incorrect 0 ms 204 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 Incorrect 0 ms 204 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 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 1 ms 204 KB Output is correct
10 Correct 1 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 Incorrect 0 ms 204 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 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 1 ms 204 KB Output is correct
10 Correct 1 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 Incorrect 0 ms 204 KB Output isn't correct
14 Halted 0 ms 0 KB -