QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#734489#9540. Double 11ucup-team3646WA 1ms3972kbC++203.0kb2024-11-11 11:25:382024-11-11 11:25:38

Judging History

你现在查看的是最新测评结果

  • [2024-11-11 11:25:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3972kb
  • [2024-11-11 11:25:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, l, r) for(ll i = l; i < r; i++)

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

/* ---- */
#define all(A) A.begin(), A.end()
#define elif else if
using pii = pair<ll, ll>;

bool chmin(auto &a, const auto &b) {return a > b ? a = b, 1 : 0;}
bool chmax(auto &a, const auto &b) {return a < b ? a = b, 1 : 0;}

struct IOSetup {
  IOSetup() {
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
} iosetup;

template<class T>
void print(vector<T> a) {
  for (auto x : a) cerr << x << ' ';
  cerr << endl;
}

void print(auto x) {
  cerr << x << endl;
}

template<class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cerr << head << ' ';
  print(forward<Tail>(tail)...);
}

double stop_watch(struct timespec start_time) {
    // 経過時間を秒単位で返す.
    struct timespec end_time;
    clock_gettime(CLOCK_REALTIME, &end_time);
    long long int sec = end_time.tv_sec - start_time.tv_sec;
    long long int nsec = end_time.tv_nsec - start_time.tv_nsec;
    return (double)sec + (double)nsec / (1000 * 1000 * 1000);
}


// https://noshi91.hatenablog.com/entry/2023/02/18/005856
// https://nyaannyaan.github.io/library/dp/monge-d-edge-shortest-path-enumerate.hpp

template <typename T>
vector<T> monge_shortest_path(int N, const function<T(int, int)>& f) {
  T INF = 1e100;
  vector<T> dp(N + 1, INF);
  vector<int> x(N + 1, 0);
  auto check = [&](int from, int to) {
    if (from >= to) return;
    T cost = f(from, to);
    if (dp[from] + cost < dp[to]) dp[to] = dp[from] + cost, x[to] = from;
  };
  auto dfs = [&](auto rc, int l, int r) -> void {
    if (l + 1 >= r) return;
    int m = (l + r) / 2;
    for (int i = x[l]; i <= x[r]; i++) check(i, m);
    rc(rc, l, m);
    for (int i = l + 1; i <= m; i++) check(i, r);
    rc(rc, m, r);
  };
  dp[0] = 0, check(0, N), dfs(dfs, 0, N);
  return dp;
}

using ld=long double;
ld inf=1e100;
ld phi=1.618033988749895;
int main(){
  struct timespec start_time;
  clock_gettime(CLOCK_REALTIME, &start_time);

  int n,m;
  cin>>n>>m;
  vector<ld>a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  vector<ld>cum(n+1,0);
  rep(i,n)cum[i+1]=cum[i]+a[i];

  auto calc=[&](ld x)->ld{
    auto cost=[&](int l,int r)->ld{
      return sqrtl((r-l)*(cum[r]-cum[l]))+x;
    };
    return monge_shortest_path<ld>(n,cost)[n]-m*x;
  };

  pair<ld,ld>l,ml,mr,r;
  l={0,-inf};
  r={3*sqrtl(n*cum[n]+10),-inf};
  {
    ld x=(phi-1)*l.first+(2-phi)*r.first;
    ml={x,calc(x)};
  }
  {
    ld x=(phi-1)*ml.first+(2-phi)*r.first;
    mr={x,calc(x)};
  }

  rep(i,120){
    if(ml.second>mr.second){
      r=mr;
      mr=ml;
      ld x=(phi-1)*l.first+(2-phi)*mr.first;
      ml={x,calc(x)};
    }
    else{
      l=ml;
      ml=mr;
      ld x=(phi-1)*ml.first+(2-phi)*mr.first;
      mr={x,calc(x)};
    }
  }
  cout<<fixed<<setprecision(20)<<calc(ml.first)<<endl;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3844kb

input:

4 2
1 2 3 4

output:

6.19114712955711948405

result:

ok found '6.191147130', expected '6.191147130', error '0.000000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3912kb

input:

10 3
1 2 3 4 5 6 7 8 9 10

output:

22.59162536651412858495

result:

ok found '22.591625367', expected '22.591625367', error '0.000000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

1 1
1

output:

1.00000000000000000022

result:

ok found '1.000000000', expected '1.000000000', error '0.000000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3908kb

input:

1 1
100000

output:

316.22776601683793323838

result:

ok found '316.227766017', expected '316.227766017', error '0.000000000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3972kb

input:

7 1
10 47 53 9 83 33 15

output:

41.83300132670377739774

result:

ok found '41.833001327', expected '41.833001327', error '0.000000000'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3912kb

input:

8 5
138 1702 119 1931 418 1170 840 1794

output:

233.90165455194358384849

result:

ok found '233.901654552', expected '233.901654552', error '0.000000000'

Test #7:

score: 0
Accepted
time: 1ms
memory: 3916kb

input:

58 1
888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983

output:

1355.26528768355902299092

result:

ok found '1355.265287684', expected '1355.265287684', error '0.000000000'

Test #8:

score: -100
Wrong Answer
time: 1ms
memory: 3912kb

input:

88 30
67117 31903 93080 85196 16438 97116 11907 72959 83651 41273 52873 81892 81468 51323 99992 58869 54258 7183 87358 90990 80596 41252 90769 82705 61434 8524 13575 10787 53950 96768 12062 34637 27806 70937 69653 28380 90236 3352 27537 3873 91006 89790 25369 91825 82734 5588 4539 74118 47098 84741 ...

output:

18791.41275468828460226689

result:

wrong answer 1st numbers differ - expected: '18791.4753541', found: '18791.4127547', error = '0.0000033'