QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578550 | #5667. Meeting Places | CelestialCoder# | WA | 2ms | 24452kb | C++20 | 2.7kb | 2024-09-20 19:57:11 | 2024-09-20 19:57:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const ll pr = 233811181;
const ll mod = (1ll<<31)-1;
struct Point {
ld x, y;
Point operator-(const Point& r)const {return Point{x-r.x, y-r.y};}
ld operator*(const Point& r) const {return x*r.x+y*r.y;}
ld operator^(const Point& r) const {return x*r.y-y*r.x;}
};
struct Circle{Point p; double r;};
long double dst(Point a, Point b){
return sqrt((a-b)*(a-b));
}
const int MAX_N = 2000 + 1;
ld dp[MAX_N][MAX_N];
ld cost[MAX_N][MAX_N];
Point pp[MAX_N][MAX_N];
int ss[MAX_N][MAX_N];
Point getCenter(Point a, Point b){ return {(a.x+b.x)/2, (a.y+b.y)/2};}
Point getCenter(Point a, Point b, Point c){
Point aa = b - a, bb = c - a;
auto c1 = aa*aa * 0.5, c2 = bb*bb *0.5;
auto d = aa ^ bb;
auto x = a.x + (c1 * bb.y - c2 * aa.y) / d;
auto y = a.y + (c2 * aa.x - c1 * bb.x) / d;
return {x, y};
}
Circle solve(vector<Point> v, int s){
Point p = {0, 0};
double r = 0;
int n = v.size();
for(int i=0; i<n; i++) {
if (dst(p, v[i]) > r) {
p = v[i];
r = 0;
for(int j=0; j<i; j++) {
if(dst(p, v[j]) > r) {
p = getCenter(v[i], v[j]);
r = dst(p, v[i]);
for(int k=0; k<j; k++) {
if(dst(p, v[k]) > r){
p = getCenter(v[i], v[j], v[k]);
r = dst(v[k], p);
}
}
}
}
}
pp[s][s+i] = p;
cost[s][s+i] = r;
}
return {p, r};
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N, K, X;
cin >> N >> K >> X;
vector <Point> input(N);
ll seed = X;
input[0].x = X;
input[0].y = seed = (seed*pr+1) % mod;
for(int i=1;i<N;i++){
input[i].x = seed = (seed*pr+1) % mod;
input[i].y = seed = (seed*pr+1) % mod;
}
for (int s=0; s<N; ++s) {
vector<Point> v(input.begin()+s, input.end());
solve(v, s);
}
for (int n=0; n<N; ++n) {
dp[n][1] = cost[0][n];
for (int k=2; k<=min(K, n+1); ++k) {
if (dst(pp[ss[n-1][k]][n-1], input[n]) < cost[ss[n-1][k]][n-1]) {
dp[n][k] = dp[n-1][k];
ss[n][k] = ss[n-1][k];
} else {
dp[n][k] = 1e18;
for (int t=k-2; t<n; ++t) {
dp[n][k] = min(dp[n][k], dp[t][k-1] + cost[t+1][n]);
ss[n][k] = t+1;
}
}
}
}
cout << fixed << setprecision(12) << dp[N-1][K];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 24452kb
input:
100 23 213
output:
1319350480.800732612610
result:
ok found '1319350480.8007326', expected '1319350480.8007326', error '0.0000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 9996kb
input:
10 1 1060
output:
1042753143.345167636871
result:
ok found '1042753143.3451676', expected '1042753143.3451676', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 11988kb
input:
10 10 2373
output:
0.000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 12280kb
input:
10 2 3396
output:
1236610536.946923017502
result:
ok found '1236610536.9469230', expected '1236610536.9469230', error '0.0000000'
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 14104kb
input:
10 3 1998
output:
0.000000000000
result:
wrong answer 1st numbers differ - expected: '973790809.8224442', found: '0.0000000', error = '1.0000000'