Submission #1040100

#TimeUsernameProblemLanguageResultExecution timeMemory
1040100AndreySki 2 (JOI24_ski2)C++14
0 / 100
1791 ms426632 KiB
#include<bits/stdc++.h> using namespace std; long long dp[301][601][301]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n,br,h,c; cin >> n >> br; vector<pair<long long,long long>> haha(n); vector<long long> idk(601,INT_MAX); for(long long i = 0; i < n; i++) { cin >> h >> c; idk[h] = min(idk[h],c); haha[i] = {h,c}; } for(long long i = 1; i <= 600; i++) { idk[i] = min(idk[i],idk[i-1]); } sort(haha.begin(),haha.end()); haha.push_back({INT_MAX,INT_MAX}); reverse(haha.begin(),haha.end()); for(long long i = n-1; i >= 1; i--) { haha[i] = {haha[i].first,min(haha[i].second,haha[i+1].second)}; } for(long long i = 0; i < 301; i++) { for(long long j = 0; j < 601; j++) { for(long long k = 0; k < 301; k++) { dp[i][j][k] = LLONG_MAX/10; } } } for(long long i = 0; i <= 601; i++) { dp[0][i][0] = 0; } for(long long i = 1; i <= n; i++) { for(long long j = 100; j >= 0; j--) { for(long long k = i-1; k >= 0; k--) { if(haha[k+1].first > j) { break; } dp[i][j][i-k] = dp[i][j+1][i-k]; for(long long y = 0; y <= i; y++) { dp[i][j][i-k] = min(dp[i][j][i-k],dp[k][j+1][y]+br*j*(i-k)+idk[j]*max(0LL,y-(i-k))); } } } } long long ans = LLONG_MAX; for(long long i = 0; i <= 100; i++) { ans = min(ans,dp[n][i][1]); } for(long long i = 1; i <= n; i++) { ans-=br*haha[i].first; } cout << ans; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:37:21: warning: iteration 601 invokes undefined behavior [-Waggressive-loop-optimizations]
   37 |         dp[0][i][0] = 0;
      |         ~~~~~~~~~~~~^~~
Main.cpp:36:28: note: within this loop
   36 |     for(long long i = 0; i <= 601; 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...