이 제출은 이전 버전의 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 N = 5e2 + 5;
const int mod = 1e9 + 7;
int n, k;
pair <int, int> state[N];
namespace subtask1{
const int sub = 105;
using lb = long double;
const lb inf = 1e9;
lb dp[sub][sub][sub];
void solve(){
lb ans = inf;
for (int fix = 0; fix < k; ++ fix){
for (int i = 0; i <= fix; ++ i){
for (int j = 0; j <= k - fix; ++ j) dp[0][i][j] = inf;
}
dp[0][0][0] = 0;
for (int i = 1; i <= n; ++ i){
lb a = state[i].se, b = state[i].fi;
for (int j = 0; j <= fix; ++ j){
for (int t = 0; t <= k - fix; ++ t){
dp[i][j][t] = dp[i - 1][j][t];
if (t) dp[i][j][t] = min(dp[i][j][t], dp[i - 1][j][t - 1] + a / (fix + 1));
if (j && b != -1) dp[i][j][t] = min(dp[i][j][t], dp[i - 1][j - 1][t] + b / j);
}
}
}
ans = min(ans, dp[n][fix][k - fix]);
}
cout << fixed << setprecision(10) << ans;
}
}
namespace ac{
using lb = long double;
void minl(lb &a, lb b){
a = min(a, b);
}
const lb inf = 1e9;
lb dp[N][N], ans = inf;
lb calc(int fix){
for (int i = 0; i <= n; ++ i)
for (int j = 0; j <= k; ++ j) dp[i][j] = inf;
dp[0][0] = 0;
for (int i = 0; i < n; ++ i){
lb a = state[i + 1].se, b = state[i + 1].fi;
for (int j = 0; j <= min(k, i); ++ j) if (dp[i][j] != inf){
if (j < fix){
minl(dp[i + 1][j], dp[i][j] + a / (fix + 1));
if (j < fix - 1) minl(dp[i + 1][j + 1], dp[i][j] + b / (j + 1));
else minl(dp[i + 1][i + 1], dp[i][j] + b / (j + 1));
}
else {
minl(dp[i + 1][j], dp[i][j]);
minl(dp[i + 1][j + 1], dp[i][j] + a / (fix + 1));
}
}
}
ans = min(ans, dp[n][k]);
return dp[n][k];
}
void solve(){
ans = calc(0);
int l = 0, r = k - 2;
while (l <= r){
int mid = l + r >> 1;
if (calc(mid) > calc(mid + 1)) l = mid + 1;
else r = mid - 1;
}
cout << fixed << setprecision(10) << ans;
}
}
void solve(){
cin >> n >> k;
for (int i = 1; i <= n; ++ i){
cin >> state[i].se >> state[i].fi;
if (state[i].fi == -1) state[i].fi = mod;
}
sort(state + 1, state + n + 1);
ac::solve();
//if (n <= 100) subtask1::solve();
//else ac::solve();
}
int main(){
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: In function 'void ac::solve()':
Main.cpp:96:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
96 | int mid = l + r >> 1;
| ~~^~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |