Submission #1062673

#TimeUsernameProblemLanguageResultExecution timeMemory
1062673AndreySki 2 (JOI24_ski2)C++14
86 / 100
606 ms491088 KiB
#include<bits/stdc++.h> using namespace std; long long dp[301][301][301]; long long wow[301][301][301]; deque<pair<long long,long long>> troll[301][301]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n,br,h,c,ans = LLONG_MAX; cin >> n >> br; vector<pair<long long,long long>> haha(n+1,{-1,-1}); vector<long long> idk(0); vector<long long> wut(0); vector<long long> pos(0); for(long long i = 0; i < n; i++) { cin >> h >> c; wut.push_back(h); haha[i+1] = {h,c}; } sort(wut.begin(),wut.end()); sort(haha.begin(),haha.end()); long long sb = 0,sm = haha[1].second; for(long long i = 1; i < wut.size(); i++) { if(wut[i] == wut[i-1]) { sb++; } else { long long y = wut[i-1]; sb++; while(y < wut[i] && sb > 0) { sb--; pos.push_back(y); idk.push_back(sm); y++; } } sm = min(sm,haha[i+1].second); } long long y = wut[wut.size()-1]; sb++; while(pos.size() <= 310) { sb--; pos.push_back(y); idk.push_back(sm); y++; } vector<int> col(310); vector<int> no(310); int z = 1; for(int i = 0; i < 310; i++) { if(i == 0 || pos[i]-pos[i-1] > 1) { col[i] = pos[i]; } else { col[i] = col[i-1]; } while(z <= n && haha[z].first <= pos[i]) { no[z] = col[i]; z++; } } for(long long i = 0; i < 301; i++) { for(long long j = 0; j < 301; j++) { for(long long k = 0; k < 301; k++) { dp[i][j][k] = LLONG_MAX/10; wow[i][j][k] = LLONG_MAX/10; } } } for(long long i = 0; i <= 300; i++) { dp[1][i][1] = pos[0]*br; } for(long long j = 0; j <= 300; j++) { for(long long y = 0; y <= 300; y++) { long long c = dp[1][j][y]-br*pos[j+1]; troll[j][y].push_back({c,1}); while(!troll[j][y].empty() && (troll[j][y][0].second <= 1-y || no[troll[j][y][0].second+1] != col[j+1])) { troll[j][y].pop_front(); } } } for(long long y = 1; y <= 300; y++) { for(long long j = 0; j <= 300; j++) { wow[1][j][y] = min(wow[1][j][y-1],dp[1][j][y]-y*idk[j]); } } for(long long i = 2; i <= n; i++) { for(long long j = 1; j <= 300; j++) { if(pos[j] < haha[i].first) { continue; } for(long long k = i-1; k >= 1; k--) { if(idk[j-1] < LLONG_MAX/10 || no[k+1] != col[j]) { dp[i][j][i-k] = min(dp[i][j][i-k],wow[k][j-1][i-k]+(i-k)*br*pos[j]+(i-k)*idk[j-1]); } } } for(long long j = 0; j < 300; j++) { for(long long y = 0; y <= i; y++) { if(pos[j+1] >= haha[i].first && !troll[j][y].empty()) { dp[i][j+1][y] = min(dp[i][j+1][y],troll[j][y][0].first+i*pos[(j+1)]*br); } } } for(long long j = 1; j <= 300; j++) { for(long long y = 0; y <= 300; y++) { dp[i][j][y] = min(dp[i][j][y],dp[i][j-1][y]); } } for(long long j = 0; j <= 300; j++) { for(long long y = 1; y <= i; y++) { long long c = dp[i][j][y]-i*br*pos[(j+1)]; while(!troll[j][y].empty() && troll[j][y][troll[j][y].size()-1].first > c) { troll[j][y].pop_back(); } troll[j][y].push_back({c,i}); while(!troll[j][y].empty() && (troll[j][y][0].second <= i-y || no[troll[j][y][0].second+1] != col[j+1])) { troll[j][y].pop_front(); } } } for(long long y = 1; y <= 300; y++) { for(long long j = 0; j <= 300; j++) { if(idk[j] < LLONG_MAX/10) { wow[i][j][y] = min(wow[i][j][y-1],dp[i][j][y]-y*idk[j]); } } } } for(long long i = 0; i <= n; i++) { ans = min(ans,dp[n][300][i]); } for(long long i = 1; i <= n; i++) { ans-=haha[i].first*br; } cout << ans << endl; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:27:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(long long i = 1; i < wut.size(); i++) {
      |                          ~~^~~~~~~~~~~~
#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...