QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#455945#4355. Seesawnhuang685#0 0ms4052kbC++201.4kb2024-06-27 03:55:222024-06-27 03:55:22

Judging History

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

  • [2024-06-27 03:55:22]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:4052kb
  • [2024-06-27 03:55:22]
  • 提交

answer

#include <bits/stdc++.h>

using db = long double;

auto main() -> int {
  std::cin.tie(nullptr)->sync_with_stdio(false);

  int n;
  std::cin >> n;
  std::vector<int> a(n);
  int64_t sum = 0;
  for (auto &i : a) {
    std::cin >> i;
    sum += i;
  }
  db avg = 1.0l * sum / n;
  int li = 0, ri = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (a[i] <= avg && avg <= a[i + 1]) {
      if (avg - a[i] <= a[i + 1] - avg) {
        li = ri = i;
      } else {
        li = ri = i + 1;
      }
    }
  }
  db l = a[li], r = a[li];
  db csum = a[li];
  for (int i = 0; i < n - 1; ++i) {
    if (li == 0) {
      csum += a[ri + 1];
      ++ri;
      l = std::min(l, csum / (i + 2));
      r = std::max(r, csum / (i + 2));
    } else if (ri == n - 1) {
      csum += a[li - 1];
      --li;
      l = std::min(l, csum / (i + 2));
      r = std::max(r, csum / (i + 2));
    } else {
      db avg1 = (csum + a[li - 1]) / (i + 2);
      db avg2 = (csum + a[ri + 1]) / (i + 2);
      if (l <= avg1 && avg1 <= r) {
        csum += a[li - 1];
        --li;
      } else if (l <= avg2 && avg2 <= r) {
        csum += a[ri + 1];
        ++ri;
      } else if (l - avg1 <= avg2 - r) {
        csum += a[li - 1];
        --li;
        l = avg1;
      } else {
        csum += a[ri + 1];
        ++ri;
        r = avg2;
      }
    }
  }
  std::cout << std::fixed << std::setprecision(10) << r - l << '\n';
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

2
925278587 966813970

output:

20767691.5000000000

result:

ok found '20767691.500000000', expected '20767691.500000000', error '0.000000000'

Test #2:

score: -1
Wrong Answer
time: 0ms
memory: 3812kb

input:

20
7902238 121690240 160345001 255257832 269315023 288280211 296247186 353929891 494812700 530994847 567379029 567478415 612943598 644028258 654380821 696407711 708542915 738196686 743020754 760907139

output:

57459167.2500000000

result:

wrong answer 1st numbers differ - expected: '52991294.1666667', found: '57459167.2500000', error = '0.0843133'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%