QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#442721#8524. Weather Forecastucup-team087#WA 0ms3860kbC++142.2kb2024-06-15 13:21:282024-06-15 13:21:28

Judging History

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

  • [2024-06-15 13:21:28]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3860kb
  • [2024-06-15 13:21:28]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


int N, K;
vector<int> A;

vector<int> ASum;

// >= thr
int solve(double thr) {
  auto at = [&](int i) -> double {
    return ASum[i] - thr * i;
  };
  const double b0 = at(0);
  const double bN = at(N);
  vector<double> lis;
  for (int i = 1; i < N; ++i) {
    const double b = at(i);
    if (b0 <= b && b <= bN) {
      auto it = lower_bound(lis.begin(), lis.end(), b);
      if (it != lis.end()) {
        *it = b;
      } else {
        lis.push_back(b);
      }
    }
  }
  return 1 + (int)lis.size();
}

int main() {
  for (; ~scanf("%d%d", &N, &K); ) {
    A.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d", &A[i]);
    }
    
    ASum.assign(N + 1, 0);
    for (int i = 0; i < N; ++i) {
      ASum[i + 1] = ASum[i] + A[i];
    }
    
    double lo = 0, hi = 1000;
    for (int iter = 0; iter < 30; ++iter) {
      const double mid = (lo + hi) / 2.0;
      ((solve(mid) >= K) ? lo : hi) = mid;
    }
    printf("%.12f\n", lo);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7 3
1 3 1 2 2 2 1

output:

1.666666008532

result:

ok found '1.66667', expected '1.66667', error '0.00000'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3860kb

input:

1 1
1

output:

999.999999068677

result:

wrong answer 1st numbers differ - expected: '1.00000', found: '1000.00000', error = '999.00000'