답안 #701349

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701349 2023-02-21T03:38:45 Z Do_you_copy K개의 묶음 (IZhO14_blocks) C++17
0 / 100
63 ms 160956 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define int long long
using namespace std;
using ll = long long;
using pii = pair <int, int>;

const int maxN = 1e5 + 1000;
const ll inf = 0x3f3f3f3f3f3f3f3f;
//const int Mod =
int n, k;

ll dp[maxN][203];
int a[maxN];

void Solve(int x){
    vector <pair <int, ll>> S;
    vector <ll> T;
    S.pb({0, dp[0][x - 1]});
    T.pb(dp[0][x - 1]);
    for (int i = 1; i <= n; ++i){
        ll minn = dp[S.back().fi][x - 1];
        while (!S.empty() && a[S.back().fi] <= a[i]){
            minn = min(minn, S.back().se);
            T.pop_back();
            S.pop_back();
        }
        dp[i][x] = min(minn + a[i], T.back());
        S.pb({i, minn});
        T.pb(min(T.back(), minn + a[i]));
        //cerr << dp[i][x] << " ";
    }
    //cerr << "\n";
}

void Init(){
    cin >> n >> k;
    memset(dp, 0x3f, sizeof(dp));
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    dp[0][0] = 0;
    for (int i = 1; i <= k; ++i){
        Solve(i);
    }
    cout << dp[n][k];
}

#define taskname "test"
signed main(){
    faster
    if (fopen(taskname ".inp", "r")){
        freopen(taskname ".inp", "r", stdin);
        freopen(taskname ".out", "w", stdout);
    }
    int tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    if (fopen("timeout.txt", "r")){
        ofstream timeout("timeout.txt");
        cerr << "Time elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n";
        timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000);
        timeout.close();
    }
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen(taskname ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen(taskname ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 160716 KB Output is correct
2 Incorrect 59 ms 160696 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 160708 KB Output is correct
2 Incorrect 63 ms 160956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 160716 KB Output is correct
2 Incorrect 59 ms 160696 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 160716 KB Output is correct
2 Incorrect 59 ms 160696 KB Output isn't correct
3 Halted 0 ms 0 KB -