Submission #1295954

#TimeUsernameProblemLanguageResultExecution timeMemory
1295954rxlfd314Ski 2 (JOI24_ski2)C++20
17 / 100
182 ms1892 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ari2 = array<int, 2>; using ari3 = array<int, 3>; using arl2 = array<ll, 2>; using arl3 = array<ll, 3>; template <class T> using vt = vector<T>; #define all(x) begin(x), end(x) #define size(x) (int((x).size())) #define REP(a,b,c,d) for(int a=(b);(d)>0?a<=(c):a>=(c);a+=(d)) #define FOR(a,b,c) REP(a,b,c,1) #define ROF(a,b,c) REP(a,b,c,-1) template <class T> T &chmin(T &a, const T &b) { a = min(a, b); return a; } signed main() { #ifndef DEBUG ios_base::sync_with_stdio(false); cin.tie(nullptr); #endif int N, K; cin >> N >> K; vt<int> H(N), C(N), hh = {-1}; FOR(i, 0, N - 1) { cin >> H[i] >> C[i]; hh.push_back(H[i]); hh.push_back(H[i] + 1); } sort(all(hh)); FOR(i, 1, N) hh[i] = max(hh[i], hh[i - 1] + 1); vt<int> cnt(size(hh)), min_C(size(hh), (int)1e9); FOR(i, 0, N - 1) { const int j = lower_bound(all(hh), H[i]) - hh.begin(); cnt[j]++, chmin(min_C[j], C[i]); } vt<vt<ll>> dp(N + 1, vt<ll>(N + 1, LLONG_MAX)), dp2; dp[0][1] = 0; int min_c = 1e9; FOR(hi, 1, size(hh) - 1) { dp2.assign(N + 1, vt<ll>(N + 1, LLONG_MAX)); FOR(i, 0, N) FOR(j, 0, N) if (dp[i][j] < LLONG_MAX && __int128(hh[hi] - hh[hi - 1]) * i * K < 1e15) chmin(dp2[min(N, max(i + cnt[hi] - j, 0))][j], dp[i][j] + 1ll * (hh[hi] - hh[hi - 1]) * i * K); chmin(min_c, min_C[hi]); FOR(i, 0, N) FOR(j, 0, N - 1) if (dp2[i][j] < LLONG_MAX) chmin(dp2[i][j + 1], dp2[i][j] + min_c); swap(dp, dp2); } cout << *min_element(all(dp[0])) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...