QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#737131 | #5667. Meeting Places | SanguineChameleon# | WA | 1ms | 4184kb | C++20 | 5.3kb | 2024-11-12 14:43:58 | 2024-11-12 14:43:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i=a;i<(b);++i)
template <class T> int sign(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
typedef Point P;
T x, y;
explicit Point(T x = 0, T y = 0): x(x), y(y) {}
bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
P operator+(P p) const { return P(x+p.x, y+p.y); }
P operator-(P p) const { return P(x-p.x, y-p.y); }
P operator*(T d) const { return P(x*d, y*d); }
P operator/(T d) const { return P(x/d, y/d); }
T dot(P p) const { return P(x*p.x + y*p.y); }
T cross(P p)const {return x*p.y - y*p.x;}
T cross(P a, P b)const {return (a-*this).cross(b-*this);}
T dist2() const{return x*x + y*y;}
double dist() const {return sqrt((double)dist2());}
//...
P perp() const{return P(-y, x);}
//...
friend ostream& operator<< (ostream& os, P p) {
return os << "(" << p.x << "," << p.y << ")";
}
};
typedef Point<double>P;
double ccRadius(const P& A, const P& B, const P& C) {
return (B-A) .dist() * (C-B).dist() * (A-C).dist()/
abs((B-A).cross(C-A))/2;
}
P ccCenter(const P&A, const P&B, const P& C) {
P b = C-A, c = B-A;
return A + (b*c.dist2() - c*b.dist2()).perp()/b.cross(c)/2;
}
void justDoIt();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
justDoIt();
return 0;
}
const long long BASE = 233811181;
const long long MOD = (1LL << 31) - 1;
int n,k;
pair<double,int> monge(int lambda, vector<vector<double>>& cost){
vector<pair<double,int>> dp(n+1);
dp[0]=make_pair(0.0,0);
for(int i=1;i<=n;i++){
dp[i]=make_pair(cost[1][i]+lambda,1);
for(int j=0;j<i;j++){
dp[i] = min(dp[i], make_pair(dp[j].first + cost[j+1][i] + lambda, dp[j].second+1) );
}
}
return dp[n];
}
void dnc(int l, int r, int low, int high, vector<double>& curDp, vector<double>& nxtDp, vector<vector<double>>& cost) {
if (l > r) {
return;
}
int m = (l + r) / 2;
int opt = -1;
for (int i = low; i <= min(high, m); i++) {
if (nxtDp[m] > curDp[i - 1] + cost[i][m]) {
nxtDp[m] = curDp[i - 1] + cost[i][m];
opt = i;
}
}
dnc(l, m - 1, low, opt, curDp, nxtDp, cost);
dnc(m + 1, r, opt, high, curDp, nxtDp, cost);
}
void justDoIt() {
cin >> n >> k;
vector<long long> x(n + 1);
vector<long long> y(n + 1);
cin >> x[1];
for (int i = 1; i <= n; i++) {
if (i > 1) {
x[i] = (y[i - 1] * BASE + 1) % MOD;
}
y[i] = (x[i] * BASE + 1) % MOD;
}
vector<P> ps(n);
for (int i = 0; i < n; i++) {
ps[i] = Point((double)x[i + 1], (double)y[i + 1]);
}
vector<vector<double>> cost(n+1, vector<double>(n+1, 0));
for (int l = 0; l < n; l++) {
P o = ps[l];
double r = 0, eps = 1+1e-8;
vector<double> res;
rep(i,l,sz(ps)) { if((o-ps[i]).dist() > r * eps){
o = ps[i], r=0;
rep(j,l,i)if((o-ps[j]).dist() > r*eps){
o = (ps[i]+ps[j])/2;
r = (o-ps[i]).dist();
rep(k,l,j) if((o-ps[k]).dist()>r*eps){
o = ccCenter(ps[i], ps[j], ps[k]);
r = (o-ps[i]).dist();
}
}
}
cost[l+1][i+1] = r;
}
}
cout << fixed << setprecision(10);
/* double lo=0,hi=1e30,mid;
//monge: returns (cost, no. of times lambda was used)
while(hi-lo > (1e-8)){
mid = (lo+hi)/2;
if(monge(mid,cost).first>k)hi=mid;
else lo=mid;
}
pair<double,int> ans = monge(lo,cost);
cout<<ans.first-(ans.second*lo)<<'\n';*/
/* for (int a = 1; a <= n; a++) {
for (int b = a; b <= n; b++) {
for (int c = b; c <= n; c++) {
for (int d = c; d <= n; d++) {
double c1 = cost[a][d] + cost[b][c];
double c2 = cost[a][c] + cost[b][d];
if (c1 > c2) {
cout << "NOPE " << c1 << " " << c2 << endl;
return;
}
}
}
}
}*/
/* vector<double> curDp(n + 1);
for (int i = 1; i <= n; i++) {
curDp[i] = cost[1][i];
}
double res = curDp[n];
for (int iter = 1; iter < k; iter++) {
vector<double> nxtDp(n + 1, 1e30);
nxtDp[0] = 0;
dnc(1, n, 1, n, curDp, nxtDp, cost);
curDp.swap(nxtDp);
res = min(res, curDp[n]);
}
cout << res << endl;*/
//dp[i][j] = i groups, first j
vector<vector<double>> dp(k + 1, vector<double>(n + 1, 1e30));
dp[0][0] = 0;
for(int j=1;j<=n;j++)dp[0][j]=1e30;
for (int i = 1; i <= k; i++){
dp[i][0]=0;
for(int j=1;j<=n;j++){
dp[i][j]=1e30;
for(int x=max(0, j - (n / k) * 10);x<j;x++){
dp[i][j] = min(dp[i][j], dp[i-1][x] + cost[x+1][j]);
}
for(int x=0;x<min(j, (n / k) * 10);x++){
dp[i][j] = min(dp[i][j], dp[i-1][x] + cost[x+1][j]);
}
}
}
cout<<dp[k][n];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3920kb
input:
100 23 213
output:
1319350480.8007326126
result:
ok found '1319350480.8007326', expected '1319350480.8007326', error '0.0000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
10 1 1060
output:
1042753143.3451676369
result:
ok found '1042753143.3451676', expected '1042753143.3451676', error '0.0000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3972kb
input:
10 10 2373
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3980kb
input:
10 2 3396
output:
1236610536.9469230175
result:
ok found '1236610536.9469230', expected '1236610536.9469230', error '0.0000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
10 3 1998
output:
973790809.8224442005
result:
ok found '973790809.8224442', expected '973790809.8224442', error '0.0000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 4056kb
input:
10 4 562
output:
910867389.9069329500
result:
ok found '910867389.9069330', expected '910867389.9069330', error '0.0000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
10 5 6048
output:
818240814.7105150223
result:
ok found '818240814.7105150', expected '818240814.7105150', error '0.0000000'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
10 6 2524
output:
500106979.3467763066
result:
ok found '500106979.3467763', expected '500106979.3467762', error '0.0000000'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
10 7 5415
output:
559478971.4320058823
result:
ok found '559478971.4320059', expected '559478971.4320059', error '0.0000000'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
10 8 1438
output:
500309745.4627699852
result:
ok found '500309745.4627700', expected '500309745.4627700', error '0.0000000'
Test #11:
score: 0
Accepted
time: 0ms
memory: 4036kb
input:
10 9 3172
output:
162279748.8753451705
result:
ok found '162279748.8753452', expected '162279748.8753452', error '0.0000000'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
100 1 8316
output:
1320052902.1522903442
result:
ok found '1320052902.1522903', expected '1320052902.1522903', error '0.0000000'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3980kb
input:
100 100 4179
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
100 12 3405
output:
1329687126.1304550171
result:
ok found '1329687126.1304550', expected '1329687126.1304548', error '0.0000000'
Test #15:
score: 0
Accepted
time: 1ms
memory: 3912kb
input:
100 16 8378
output:
1338056514.4842693806
result:
ok found '1338056514.4842694', expected '1338056514.4842694', error '0.0000000'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3900kb
input:
100 2 1858
output:
1310392496.1430580616
result:
ok found '1310392496.1430581', expected '1310392496.1430581', error '0.0000000'
Test #17:
score: 0
Accepted
time: 1ms
memory: 3980kb
input:
100 25 4596
output:
1440464106.6229298115
result:
ok found '1440464106.6229298', expected '1440464106.6229298', error '0.0000000'
Test #18:
score: 0
Accepted
time: 1ms
memory: 3936kb
input:
100 3 5633
output:
1399621082.6142737865
result:
ok found '1399621082.6142738', expected '1399621082.6142738', error '0.0000000'
Test #19:
score: 0
Accepted
time: 1ms
memory: 4056kb
input:
100 32 7827
output:
1342073760.5322329998
result:
ok found '1342073760.5322330', expected '1342073760.5322330', error '0.0000000'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
100 4 3693
output:
1339808706.7098686695
result:
ok found '1339808706.7098687', expected '1339808706.7098689', error '0.0000000'
Test #21:
score: 0
Accepted
time: 1ms
memory: 3904kb
input:
100 5 2252
output:
1394874243.5057041645
result:
ok found '1394874243.5057042', expected '1394874243.5057042', error '0.0000000'
Test #22:
score: -100
Wrong Answer
time: 1ms
memory: 4184kb
input:
100 50 4254
output:
1395104828.8878018856
result:
wrong answer 1st numbers differ - expected: '1322809748.4052832', found: '1395104828.8878019', error = '0.0546527'