Submission #1266410

#TimeUsernameProblemLanguageResultExecution timeMemory
1266410thelegendary08Ski 2 (JOI24_ski2)C++17
100 / 100
192 ms217236 KiB
#include<bits/stdc++.h> #define pb push_back #define mp make_pair #define int long long #define vi vector<int> #define vvi vector<vector<int>> #define pii pair<int, int> #define vpii vector<pair<int, int>> #define vc vector<char> #define vb vector<bool> #define mii map<int,int> #define f0r(i,n) for(int i=0;i<n;i++) #define FOR(i,k,n) for(int i=k;i<n;i++) #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define in(a) int a; cin>>a #define in2(a,b) int a,b; cin>>a>>b #define in3(a,b,c) int a,b,c; cin>>a>>b>>c #define in4(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d #define vin(v,n); vi v(n); f0r(i,n){cin>>v[i];} #define out(a) cout<<a<<'\n' #define out2(a,b) cout<<a<<' '<<b<<'\n' #define out3(a,b,c) cout<<a<<' '<<b<<' '<<c<<'\n' #define out4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<'\n' #define pout(a) cout<<a.first<<' '<<a.second<<'\n' #define vout(v) for(auto u : v){cout<<u<<' ';} cout<<endl #define dout(a) cout<<a<<' '<<#a<<endl #define dout2(a,b) cout<<a<<' '<<#a<<' '<<b<<' '<<#b<<endl #define yn(x); if(x){cout<<"YES"<<'\n';}else{cout<<"NO"<<'\n';} const int leg = 1e9 + 7; const int mod = 998244353; using namespace std; const int mxn = 305; int n, K, h[mxn], c[mxn], cnt[mxn], dp[mxn][mxn][mxn], lsh[mxn], cst[mxn]; signed main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin>>n>>K; f0r(i,n){ cin>>h[i]>>c[i]; lsh[i] = h[i]; } sort(lsh, lsh + n); FOR(i,1,n)lsh[i] = max(lsh[i-1] + 1, lsh[i]); //lsh[i] decompresses i f0r(i,n)h[i] = lower_bound(lsh, lsh + n, h[i]) - lsh; f0r(i,n)cst[i] = 4e18; f0r(i,n)cst[h[i]] = min(cst[h[i]], c[i]); FOR(i,1,n)cst[i] = min(cst[i], cst[i-1]); f0r(i,n)cnt[h[i]]++; f0r(i,n)f0r(j,n+1)f0r(k,n+1)dp[i][j][k] = 1e15; dp[0][1][cnt[0]-1] = 0; f0r(i,n-1)f0r(j,n+1)f0r(k,n+1){ int nx = k+cnt[i+1]; int muc; if(k && (lsh[i+1] - lsh[i]) * K > 1e15)muc = 1e15; else muc = k * (lsh[i+1] - lsh[i]) * K; if(nx <= n){ dp[i+1][j][nx] = min(dp[i+1][j][nx],dp[i][j][k]+muc); if(nx>j){ dp[i+1][j][nx-j] = min(dp[i+1][j][nx-j],dp[i][j][k]+muc); if(j != n && nx-j != 0)dp[i+1][j+1][nx-j-1] = min(dp[i+1][j+1][nx-j-1], dp[i+1][j][nx-j] + cst[i]); } else dp[i+1][j][0] = min(dp[i+1][j][0], dp[i][j][k]+muc); } } int ans = 4e18; f0r(i, n+1)ans = min(ans, dp[n-1][i][0]); out(ans); }
#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...