QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#455946#4355. Seesawnhuang685#0 0ms3856kbC++201.5kb2024-06-27 03:56:262024-06-27 03:56:27

Judging History

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

  • [2024-06-27 03:56:27]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3856kb
  • [2024-06-27 03:56:26]
  • 提交

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 = std::min<db>(avg, a[li]), r = std::max<db>(avg, 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: 3856kb

input:

2
925278587 966813970

output:

20767691.5000000000

result:

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

Test #2:

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

input:

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

output:

52991294.1666666667

result:

ok found '52991294.166666664', expected '52991294.166666687', error '0.000000000'

Test #3:

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

input:

20
37698309 122861191 172244451 227579326 314637638 425599056 429200117 531049382 548293537 557767688 600249369 625965962 703410128 707452380 747227710 753853272 821738507 858449772 859150731 988518805

output:

39435606.5803571429

result:

wrong answer 1st numbers differ - expected: '37041534.6529411', found: '39435606.5803571', error = '0.0646321'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%