이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
i64 c[2005][2005];
i64 big[2005];
void f(int y1, int y2, int x1, int x2)
{
if (y1 > y2 || x1 > x2)
return;
i64 ans = -1ll << 60;
i64 ansp = x1;
int y = (y1 + y2) / 2;
for (int i = x1; i <= x2; i++)
{
if (c[y][i] > ans)
{
ans = c[y][i];
ansp = i;
}
}
big[y] = ans;
f(y1, y - 1, x1, ansp);
f(y + 1, y2, ansp, x2);
}
int main()
{
int n, m;
scanf("%d %d", &n, &m);
vector<ii64> cakes(n);
for (int i = 0; i < n; i++)
scanf("%lld %lld", &cakes[i].xx, &cakes[i].yy);
for (int i = 0; i < n; i++)
big[i] = -1ll << 60;
sort(all(cakes), [](const ii64& l, const ii64& r)
{
return l.yy < r.yy;
});
// c(i,j) 전처리
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
c[i][j] = -1ll << 60;
for (int sc = 0; sc < n; sc++)
{
multiset<i64> largest;
i64 sum = cakes[sc].xx;
for (int bc = sc + 2; bc < n; bc++)
{
if (largest.size() < m - 2)
{
largest.insert(cakes[bc - 1].xx);
sum += cakes[bc - 1].xx;
}
else if (*largest.begin() < cakes[bc - 1].xx)
{
sum += cakes[bc - 1].xx;
sum -= *largest.begin();
largest.erase(largest.begin());
largest.insert(cakes[bc - 1].xx);
}
i64 total = sum + cakes[bc].xx - 2 * (cakes[bc].yy - cakes[sc].yy);
if (largest.size() == m - 2)
c[sc][bc] = total;
}
}
f(0, n - 1, 0, n - 1);
i64 ans = big[0];
for (int i = 1; i < n; i++)
ans = max(ans, big[i]);
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
cake3.cpp: In function 'int main()':
cake3.cpp:85:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (largest.size() < m - 2)
~~~~~~~~~~~~~~~^~~~~~~
cake3.cpp:100:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (largest.size() == m - 2)
~~~~~~~~~~~~~~~^~~~~~~~
cake3.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
cake3.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &cakes[i].xx, &cakes[i].yy);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |