QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578722 | #5667. Meeting Places | CelestialCoder# | WA | 0ms | 22776kb | C++20 | 3.9kb | 2024-09-20 20:59:47 | 2024-09-20 20:59:52 |
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; ld r;};
ld 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};
ld 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);
}
vector<vector<int>> improved(N+1);
for (int i=0; i<=N; ++i) improved[i].push_back(0);
for (int n=0; n<N; ++n) {
dp[n][1] = cost[0][n];
improved[1].push_back(n);
for (int k=2; k<=min(K, n+1); ++k) {
if (k != n+1 && 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];
assert(improved[k].back() == n-1);
improved[k].back() = n;
} else {
dp[n][k] = 1e18;
for (int i=(int)improved[k-1].size()-1; i>=0; --i) {
int t = improved[k-1][i];
if (t < k-2) break;
if (t == n) continue;
dp[n][k] = min(dp[n][k], dp[t][k-1] + cost[t+1][n]);
ss[n][k] = t+1;
}
improved[k].push_back(n);
}
}
}
/*
for (int n=0; n<N; ++n) {
dp[n][1] = cost[0][n];
for (int k=2; k<=min(K, n+1); ++k) {
if (k != n+1 && dst(pp[ss[n-1][k]][n-1], input[n]) < cost[ss[n-1][k]][n-1]) {
// cout << n << ' ' << k << ", " << ss[n-1][k] << ' ' << cost[ss[n-1][k]][n-1] << endl;
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 << n << ' ' << k << ' ' << dp[n][k] << endl;
}
}
*/
cout << fixed << setprecision(12);
cout << dp[N-1][K];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 22776kb
input:
100 23 213
output:
544289597.434147032152
result:
wrong answer 1st numbers differ - expected: '1319350480.8007326', found: '544289597.4341470', error = '0.5874564'