QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#801481#9540. Double 11wangjunruiWA 1ms3736kbC++143.1kb2024-12-07 00:31:512024-12-07 00:31:52

Judging History

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

  • [2024-12-07 00:31:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3736kb
  • [2024-12-07 00:31:51]
  • 提交

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")


template <class T> struct MonotoneMinDP {
	vector<pair<T, int>> dp;
	vector<pair<int, int>> que;
	template <class Cost> pair<T, int> operator()(int n, Cost cost) {
		auto get = [&](int l, int r) -> pair<T, int> {
			return make_pair(dp[l].first + cost(l, r), dp[l].second + 1);
		};
		dp.resize(n + 1);
		que.resize(n + 1);
		int head = 0, tail = 1;
		que[0] = make_pair(0, 1);
		for (int i = 1; ; ++i) {
			dp[i] = get(que[head].first, i);
			if (i == n) break;
			++que[head].second;
			if (head + 1 < tail && que[head].second == que[head + 1].second) ++head;
			for (int rr = n + 1; ; --tail) {
				if (head == tail) {
					que[tail++] = make_pair(i, i + 1);
					break;
				}
				const int l = que[tail - 1].first, r = que[tail - 1].second;
				if (get(l, r) < get(i, r)) {
					int lo = r, hi = rr;
					for (; lo + 1 < hi; ) {
						const int mid = (lo + hi) / 2;
						((get(l, mid) < get(i, mid)) ? lo : hi) = mid;
					}
					if (hi <= n) que[tail++] = make_pair(i, hi);
					break;
				} else {
					rr = r;
				}
			}
		}
		return dp[n];
	}
};  // MonotoneMinDP


using Double = long double;

int N, M;
vector<Int> S, SSum;

MonotoneMinDP<Double> f;
pair<Double, int> calc(Double pena) {
	return f(N, [&](int l, int r) -> Double {
		return sqrt((Double)((r - l) * (SSum[r] - SSum[l]))) + pena;
	});
}

int main() {
	scanf("%d%d", &N, &M);
		S.resize(N);
		for (int i = 0; i < N; ++i) scanf("%lld", &S[i]);
		sort(S.begin(), S.end());
		
		SSum.assign(N + 1, 0);
		for (int i = 0; i < N; ++i) SSum[i + 1] = SSum[i] + S[i];
		
		Double lo = -1e9, hi = 1e9;
		for (int iter = 0; iter < 60; ++iter) {
			const Double mid = (lo + hi) / 2;
			const auto res = calc(mid);
//			printf("%Lf %Lf %d\n", mid, res.first, res.second);
			((res.second >= M) ? lo : hi) = mid;
		}
		const auto res = calc(lo);
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3736kb

input:

4 2
1 2 3 4

output:


result:

wrong output format Unexpected end of file - double expected