이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
long long dp[301][601][301];
long long wow[301][601][301];
deque<pair<long long,long long>> troll[601][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() <= 610) {
sb--;
pos.push_back(y);
idk.push_back(sm);
y++;
}
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;
wow[i][j][k] = LLONG_MAX/10;
}
}
}
for(long long i = pos[0]; i <= 600; i++) {
dp[1][i][1] = pos[0]*br;
}
for(long long j = 0; j <= 600; 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});
}
}
for(long long y = 1; y <= 300; y++) {
for(long long j = 0; j <= 600; 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 = max(1LL,pos[haha[i].first]); j <= 600; j++) {
for(long long k = i-1; k >= 1; k--) {
if(idk[j-1] < LLONG_MAX/10) {
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 < 600; j++) {
for(long long y = 0; y <= i; y++) {
if(pos[j+1] >= haha[i].first) {
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 <= 600; 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 <= 600; j++) {
for(long long y = 1; y <= i; y++) {
if(troll[j][y][0].second <= i-y) {
troll[j][y].pop_front();
}
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});
}
}
for(long long y = 1; y <= 300; y++) {
for(long long j = 0; j <= 600; 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][600][i]);
}
for(long long i = 1; i <= n; i++) {
ans-=haha[i].first*br;
}
cout << ans << endl;
return 0;
}
컴파일 시 표준 에러 (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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |