Submission #658046

# Submission time Handle Problem Language Result Execution time Memory
658046 2022-11-12T03:20:04 Z kusssso Stove (JOI18_stove) C++17
100 / 100
115 ms 82932 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
const ll inf = 1e18;

int n, k;
ll t[N];

namespace sub2 {
    ll dp[5005][5005];
    void solve() {
        for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = inf;
        dp[0][0] = 0;
        for (int z = 1; z <= k; z++) {
            ll min_dp = inf;
            for (int i = 1; i <= n; i++) {
                min_dp = min(min_dp, dp[i - 1][z - 1] - t[i]);
                dp[i][z] = min(dp[i][z], min_dp + t[i] + 1);
            }
        }
        cout << dp[n][k];
    }  
};

namespace full {
    void solve() {
        multiset<ll> s;
        for (int i = 2; i <= n; i++) {
            s.insert(t[i] - t[i - 1] - 1);
            if (s.size() > k - 1) {
                s.erase(s.begin());
            }
        }
        ll ans = t[n] - t[1] + 1;
        for (auto &x : s) {
            ans -= x;    
        }
        cout << ans;
    }  
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> t[i];
    if (n <= 5000) sub2::solve();
    else full::solve();
    
    return 0;
}

Compilation message

stove.cpp: In function 'void full::solve()':
stove.cpp:31:26: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |             if (s.size() > k - 1) {
      |                 ~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 34 ms 82876 KB Output is correct
11 Correct 35 ms 82880 KB Output is correct
12 Correct 63 ms 82888 KB Output is correct
13 Correct 115 ms 82932 KB Output is correct
14 Correct 109 ms 82928 KB Output is correct
15 Correct 114 ms 82928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 34 ms 82876 KB Output is correct
11 Correct 35 ms 82880 KB Output is correct
12 Correct 63 ms 82888 KB Output is correct
13 Correct 115 ms 82932 KB Output is correct
14 Correct 109 ms 82928 KB Output is correct
15 Correct 114 ms 82928 KB Output is correct
16 Correct 13 ms 1976 KB Output is correct
17 Correct 13 ms 2028 KB Output is correct
18 Correct 14 ms 1996 KB Output is correct
19 Correct 19 ms 2504 KB Output is correct
20 Correct 33 ms 4428 KB Output is correct
21 Correct 35 ms 6216 KB Output is correct
22 Correct 34 ms 6696 KB Output is correct
23 Correct 35 ms 6672 KB Output is correct
24 Correct 34 ms 6668 KB Output is correct