이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// author : thembululquaUwU
// 3.9.2024
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;
const int MaxN = 2e5;
const int mod = 1e9 + 7;
void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}
const ll inf = 1ll << 60;
template <int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
static_assert(D >= 1, "Dimension must be positive");
template <typename... Args>
Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}
};
template <typename T>
struct Vec<1, T> : public vector<T> {
Vec(int n = 0, T val = inf) : std::vector<T>(n, val) {}
};
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fd(sr, x) (lower_bound(sr.begin(), sr.end(), x) - sr.begin())
#define uq(sr) (sr).erase(unique(all((sr))), (sr).end())
#define szv(v) (int((v).size()))
int szhk(int n){
return n * (n - 1) / 2;
}
void solve(){
int n, k; cin >> n >> k;
vector <int> sr(2 * n), h(n); vector <ll> c(n);
for (int i = 0; i < n; ++ i) cin >> h[i] >> c[i], sr[i] = h[i], sr[i + n] = h[i] + 1;
sort(all(sr)); uq(sr); int sz = szv(sr);
vector <ll> cost(sz, inf); vi cnt(sz, 0);
for (int i = 0; i < n; ++ i){
int p = fd(sr, h[i]);
minl(cost[p], c[i]); ++ cnt[p];
}
Vec <3, ll> dp(sz + 1, n + 1, n + 1);
dp[0][1][0] = 0; ll ans = inf, mnc = inf;
for (int i = 0; i < sz; ++ i){
int w = n; if (i < sz - 1) w = sr[i + 1] - sr[i];
for (int d = 1; d <= n; ++ d){
for (int r = 0; r <= n; ++ r){
ll now = dp[i][d][r];
if (now == inf) continue;
if (d < n) minl(dp[i][d + 1][r], now + mnc);
int num = r + cnt[i]; ll co = 0, nr = 0;
if (1ll * d * w < 1ll * num) nr = num - d * w, co += 1ll * w * nr, num = d * w;
int bl = num / d, re = num % d;
co += 1ll * szhk(bl) * d + 1ll * re * bl; co *= k;
minl(dp[i + 1][d][nr], now + co);
}
}
minl(mnc, cost[i]);
}
for (int d = 1; d <= n; ++ d) minl(ans, dp[sz][d][0]);
cout << ans;
}
int main(){
if (fopen("pqh.inp", "r")){
freopen("pqh.inp", "r", stdin);
freopen("pqh.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1; // cin >> t;
while (t --) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp:18:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
18 | void maxl(auto &a, auto b) {a = max(a, b);}
| ^~~~
Main.cpp:18:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
18 | void maxl(auto &a, auto b) {a = max(a, b);}
| ^~~~
Main.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
19 | void minl(auto &a, auto b) {a = min(a, b);}
| ^~~~
Main.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
19 | void minl(auto &a, auto b) {a = min(a, b);}
| ^~~~
Main.cpp: In function 'int main()':
Main.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | freopen("pqh.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen("pqh.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |