#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <cmath>
#include <random>
#include <chrono>
#include <iomanip>
#include <iostream>
using namespace std;
#define double long double
int log_ = 3;
int inf = 2000000000000000000;
int mod = 1102024631;
int p = 505;
bool cmp(pair <int, int> a, pair <int, int> b)
{
if (a.second < b.second)
{
return true;
}
return false;
}
vector <pair <int, int>> vp;
int k;
double c(int col)
{
int n = vp.size();
vector <vector <double>> dp0(n + 1);
vector <vector <double>> dp1;
for (int i = 0; i <= n; i++)
{
dp0[i].resize(n + 1, inf);
}
dp0[0][0] = 0;
dp1 = dp0;
for (int k = 0; k < n; k++)
{
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= n; j++)
{
if (i > 0)
{
if (vp[k].second != -1)
{
dp1[i][j] = min(dp1[i][j], dp0[i - 1][j] + ((0. + vp[k].second) / i));
}
}
if (j > 0)
{
dp1[i][j] = min(dp1[i][j], dp0[i][j - 1] + ((0. + vp[k].first) / (col + 1)));
}
}
}
dp0 = dp1;
}
vector <double> ans_;
double ans = inf;
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= n; j++)
{
if (i + j == k)
{
if (i == col)
{
ans = min(dp0[i][j], ans);
ans_.push_back(dp0[i][j]);
}
}
}
}
return ans;
}
mt19937 rnd(15);
int rnd_(int l, int r)
{
int s = r - l + 1;
int x = rnd();
x = abs(x);
x %= (s + 1);
return l + x;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n >> k;
vp.resize(n);
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
vp[i] = { a, b };
}
sort(vp.begin(), vp.end(), cmp);
int l = 0;
int r = n;
for (int i = 0; i < n; i++)
{
if (vp[i].second == -1)
r--;
}
while (r - l > 7)
{
int m = rnd_(l , r - 1);
if (c(m) < c(m + 1))
r = m;
else
l = m+1;
}
double ans = inf;
for (int i = l; i <= r; i++)
{
ans = min(ans, c(i));
}
cout << fixed;
cout << setprecision(9);
cout << ans;
}
Compilation message
Main.cpp:21:11: warning: overflow in conversion from 'long int' to 'int' changes value from '2000000000000000000' to '1321730048' [-Woverflow]
21 | int inf = 2000000000000000000;
| ^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
788 ms |
8336 KB |
Output is correct |
6 |
Correct |
791 ms |
8284 KB |
Output is correct |
7 |
Correct |
816 ms |
8332 KB |
Output is correct |
8 |
Correct |
794 ms |
8340 KB |
Output is correct |
9 |
Correct |
789 ms |
8344 KB |
Output is correct |
10 |
Correct |
787 ms |
8280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
788 ms |
8336 KB |
Output is correct |
6 |
Correct |
791 ms |
8284 KB |
Output is correct |
7 |
Correct |
816 ms |
8332 KB |
Output is correct |
8 |
Correct |
794 ms |
8340 KB |
Output is correct |
9 |
Correct |
789 ms |
8344 KB |
Output is correct |
10 |
Correct |
787 ms |
8280 KB |
Output is correct |
11 |
Correct |
0 ms |
512 KB |
Output is correct |
12 |
Execution timed out |
2573 ms |
8284 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2543 ms |
8284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
788 ms |
8336 KB |
Output is correct |
6 |
Correct |
791 ms |
8284 KB |
Output is correct |
7 |
Correct |
816 ms |
8332 KB |
Output is correct |
8 |
Correct |
794 ms |
8340 KB |
Output is correct |
9 |
Correct |
789 ms |
8344 KB |
Output is correct |
10 |
Correct |
787 ms |
8280 KB |
Output is correct |
11 |
Correct |
0 ms |
512 KB |
Output is correct |
12 |
Execution timed out |
2573 ms |
8284 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |