Submission #647615

# Submission time Handle Problem Language Result Execution time Memory
647615 2022-10-03T10:12:16 Z thanh913 K blocks (IZhO14_blocks) C++14
0 / 100
3 ms 776 KB
#include <bits/stdc++.h>
using namespace std;

//types
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>

#define fi first
#define se second
#define inf 0x3f3f3f3f

#define pw2(x) (1LL << (x))
#define getBit(x, y) ((x) & (1LL << (y)))

template<class X, class Y>
bool cmax(X &a, const Y &b) {
    return a < b ? a = b, 1 : 0;
}

template<class X, class Y>
bool cmin(X &a, const Y &b) {
    return a > b ? a = b, 1 : 0;
}

//lowercase 31, all 53
//(P/Q) % M = (P % M) * (Q^(M-2) % M)
//-------------------------------------------------------

const ld PI = 3.14159265359;
const ll N = 1e5+5, M = 1e2+5, L = 20, mod = 1e9+7;
int n, m, ln[N][L+2], a[N], lg[N];

int get(int l, int r) {
    if (l > r) return 0;
    int j = lg[r - l + 1];
    return max(ln[l][j], ln[r - (1 << j) + 1][j]);
}

void preCompute() {
    for (int j = 1; j <= L; j++) {
        for (int i = 1; i <= n - (1 << j) + 1; i++) {
            ln[i][j] = max(ln[i][j-1], ln[i + (1 << (j-1))][j-1]);
        }
    }
    for (int i = 2; i <= n; i++) {
        lg[i] = lg[i/2] + 1;
    }
}

namespace sub1 {
    int f[1005][M];
    int solve() {
        memset(f, inf, sizeof(f));
        f[0][0] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= min(m, i); j++) {
                for (int k = 0; k < i; k++) {
                    cmin(f[i][j], f[k][j-1] + get(k+1, i));
                }
            }
        }
        return f[n][m];
    }
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    freopen("Kblocks.Inp", "r", stdin);
    freopen("Kblocks.Out", "w", stdout);

    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        ln[i][0] = a[i];
    }
    preCompute();
    if (n <= 1e3 && m <= 1e2) cout << sub1::solve();
}


Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:71:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |     freopen("Kblocks.Inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:72:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |     freopen("Kblocks.Out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -