Submission #774122

# Submission time Handle Problem Language Result Execution time Memory
774122 2023-07-05T12:10:35 Z qwerasdfzxcl Card Scoring (CCO19_day2problem1) C++17
25 / 100
3746 ms 67284 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, k;

struct Func{
	int p;
	double q;

	Func(){}
	Func(int _p, double _q): p(_p), q(_q) {}

	double operator()(int x) const{
		return pow(x-p, (double)k/2) + q;
	}
};

int cross(const Func &f, const Func &g){
	int l = g.p + 1, r = n, ans = n+1;
	
	while(l<=r){
		int mid = (l+r)>>1;
		if (f(mid) >= g(mid)) ans = mid, r = mid-1;
		else l = mid+1;
	}

	return ans;
}

struct Hull{
	vector<Func> st;

	void insert(Func g){
		// printf("insert %d %f\n", g.p, g.q);
		while(st.size() >= 2){
			if (cross(*++st.rbegin(), st.back()) > cross(st.back(), g)) break;
			st.pop_back();
		}

		st.push_back(g);
	}

	double query(int x){
		int l = 0, r = (int)st.size()-2, ans = (int)st.size()-1;
		while(l<=r){
			int mid = (l+r)>>1;
			if (st[mid](x) >= st[mid+1](x)) ans = mid, r = mid-1;
			else l = mid+1;
		}

		// for (int i=0;i<(int)st.size();i++) printf("%f ", st[i](x));
		// printf("\n");
		// printf("return: %f \n", st[ans](x));

		return st[ans](x);
	}
}H[1001000];

int a[1001000], idx[1001000], cnt[1001000];
double dp[1001000];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> k >> n;
	for (int i=1;i<=n;i++){
		cin >> a[i];
		cnt[a[i]]++;
		idx[i] = cnt[a[i]];
	}
	if (k==2){
		printf("%.15f\n", (double)n);
		return 0;
	}

	for (int i=1;i<=n;i++){
		// printf(" ok %d %f\n", idx[i]-1, dp[i-1]);
		H[a[i]].insert(Func(idx[i]-1, dp[i-1]));
		dp[i] = H[a[i]].query(idx[i]);
		// printf("%d -> %.15f\n", i, dp[i]);
	}

	printf("%.15f\n", dp[n]);
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23820 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23756 KB Output is correct
5 Correct 14 ms 23832 KB Output is correct
6 Correct 14 ms 23772 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23864 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 15 ms 23832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23864 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 15 ms 23832 KB Output is correct
4 Correct 13 ms 23864 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 15 ms 23832 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 11 ms 23764 KB Output is correct
9 Correct 12 ms 23816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23864 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 15 ms 23832 KB Output is correct
4 Correct 13 ms 23864 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 15 ms 23832 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 11 ms 23764 KB Output is correct
9 Correct 12 ms 23816 KB Output is correct
10 Correct 18 ms 23892 KB Output is correct
11 Correct 24 ms 23892 KB Output is correct
12 Correct 17 ms 23912 KB Output is correct
13 Correct 17 ms 23920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2432 ms 39632 KB Output is correct
2 Correct 2541 ms 39412 KB Output is correct
3 Correct 948 ms 31592 KB Output is correct
4 Correct 1616 ms 31892 KB Output is correct
5 Correct 1180 ms 59084 KB Output is correct
6 Correct 1448 ms 57232 KB Output is correct
7 Correct 1447 ms 57188 KB Output is correct
8 Correct 1457 ms 57116 KB Output is correct
9 Correct 1455 ms 57120 KB Output is correct
10 Correct 1503 ms 57200 KB Output is correct
11 Correct 2332 ms 39428 KB Output is correct
12 Correct 2380 ms 39500 KB Output is correct
13 Correct 2084 ms 39432 KB Output is correct
14 Correct 3041 ms 39740 KB Output is correct
15 Correct 2871 ms 39672 KB Output is correct
16 Correct 2962 ms 39692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23820 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23756 KB Output is correct
5 Correct 14 ms 23832 KB Output is correct
6 Correct 14 ms 23772 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 13 ms 23864 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 15 ms 23832 KB Output is correct
12 Correct 13 ms 23864 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 15 ms 23832 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 11 ms 23764 KB Output is correct
17 Correct 12 ms 23816 KB Output is correct
18 Correct 18 ms 23892 KB Output is correct
19 Correct 24 ms 23892 KB Output is correct
20 Correct 17 ms 23912 KB Output is correct
21 Correct 17 ms 23920 KB Output is correct
22 Correct 2432 ms 39632 KB Output is correct
23 Correct 2541 ms 39412 KB Output is correct
24 Correct 948 ms 31592 KB Output is correct
25 Correct 1616 ms 31892 KB Output is correct
26 Correct 1180 ms 59084 KB Output is correct
27 Correct 1448 ms 57232 KB Output is correct
28 Correct 1447 ms 57188 KB Output is correct
29 Correct 1457 ms 57116 KB Output is correct
30 Correct 1455 ms 57120 KB Output is correct
31 Correct 1503 ms 57200 KB Output is correct
32 Correct 2332 ms 39428 KB Output is correct
33 Correct 2380 ms 39500 KB Output is correct
34 Correct 2084 ms 39432 KB Output is correct
35 Correct 3041 ms 39740 KB Output is correct
36 Correct 2871 ms 39672 KB Output is correct
37 Correct 2962 ms 39692 KB Output is correct
38 Correct 487 ms 67284 KB Output is correct
39 Correct 2488 ms 39420 KB Output is correct
40 Correct 3430 ms 39448 KB Output is correct
41 Correct 1008 ms 31608 KB Output is correct
42 Correct 1861 ms 32080 KB Output is correct
43 Correct 1213 ms 58952 KB Output is correct
44 Correct 2067 ms 57220 KB Output is correct
45 Correct 2324 ms 39560 KB Output is correct
46 Correct 2339 ms 39408 KB Output is correct
47 Correct 2202 ms 39452 KB Output is correct
48 Correct 3401 ms 39460 KB Output is correct
49 Correct 3746 ms 39468 KB Output is correct
50 Correct 3637 ms 39544 KB Output is correct