QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#455964#4355. Seesawnhuang685#0 0ms3948kbC++201.4kb2024-06-27 04:47:412024-06-27 04:47:41

Judging History

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

  • [2024-06-27 04:47:41]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3948kb
  • [2024-06-27 04:47:41]
  • 提交

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;
  db ans = std::numeric_limits<db>::infinity();
  for (int j = 0; j < n; ++j) {
    int li = j, ri = j;
    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;
        }
      }
    }
    ans = std::min(ans, r - l);
  }
  std::cout << std::fixed << std::setprecision(10) << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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: 3916kb

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: 3828kb

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%