답안 #282596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
282596 2020-08-24T15:24:24 Z cgiosy Akvizna (COCI19_akvizna) C++17
65 / 130
999 ms 2548 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using flt=double;

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int N, K;
	cin>>N>>K;
	flt l=0, r=1;
	vector<int> C(N+1), P(N+1);
	cout<<fixed<<setprecision(9);
	auto f=[&](flt m) {
		vector<double> D(N+1);
		vector<int> T(1<<32-__builtin_clz(N));
		auto f=[&](int j, int i) {
			return D[j]+flt(i-j)/i;
		};
		auto cmp=[&](int i, int j, int x) {
			return f(i, x)>f(j, x);
		};
		auto add=[&](int a) {
			int s=1, e=N, i=1;
			while(i) {
				int m=s+e>>1, &b=T[i];
				if(cmp(a, b, m)) swap(a, b);
				if(cmp(a, b, s)) e=m-1, i=i*2;
				else if(cmp(a, b, e)) s=m+1, i=i*2+1;
				else break;
			}
		};
		auto get=[&](int x) {
			int s=1, e=N, i=1, a=0;
			while(i) {
				int m=s+e>>1, b=T[i];
				if(cmp(b, a, x)) a=b;
				if(x<m) e=m-1, i=i*2;
				else if(x>m) s=m+1, i=i*2+1;
				else break;
			}
			return a;
		};
		D[0]=0;
		for(int i=1; i<=N; i++) {
			add(i-1);
			int p=get(i);
			P[i]=p;
			C[i]=C[p]+1;
			D[i]=f(p, i)-m;
		}
		return make_pair(C[N], D[N]+K*m);
	};
	while(r-l>1e-9) {
		flt m=(l+r)/2;
		auto[k,x]=f(m);
		if(k<K) r=m;
		else if(k>K) l=m;
		else { l=r=m; break; }
	}
	cout<<fixed<<setprecision(9)<<f((l+r)/2).second;
}

Compilation message

akvizna.cpp: In lambda function:
akvizna.cpp:15:22: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   15 |   vector<int> T(1<<32-__builtin_clz(N));
      |                    ~~^~~~~~~~~~~~~~~~~
akvizna.cpp: In lambda function:
akvizna.cpp:25:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |     int m=s+e>>1, &b=T[i];
      |           ~^~
akvizna.cpp: In lambda function:
akvizna.cpp:35:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |     int m=s+e>>1, b=T[i];
      |           ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 640 KB Output is correct
2 Correct 22 ms 384 KB Output is correct
3 Correct 20 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 384 KB Output is correct
2 Correct 17 ms 384 KB Output is correct
3 Correct 21 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 384 KB Output is correct
2 Correct 17 ms 384 KB Output is correct
3 Correct 19 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 384 KB Output is correct
2 Correct 20 ms 384 KB Output is correct
3 Correct 20 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 384 KB Output is correct
2 Correct 20 ms 384 KB Output is correct
3 Correct 20 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 384 KB Output is correct
2 Correct 23 ms 384 KB Output is correct
3 Correct 23 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 384 KB Output is correct
2 Correct 22 ms 384 KB Output is correct
3 Correct 22 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 384 KB Output is correct
2 Correct 18 ms 384 KB Output is correct
3 Correct 21 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 384 KB Output is correct
2 Correct 20 ms 440 KB Output is correct
3 Correct 21 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 909 ms 2464 KB Output is correct
2 Correct 947 ms 2436 KB Output is correct
3 Incorrect 893 ms 2348 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 942 ms 2384 KB Output is correct
2 Incorrect 955 ms 2548 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 923 ms 2456 KB Output is correct
2 Incorrect 981 ms 2532 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 944 ms 2420 KB Output is correct
2 Correct 956 ms 2452 KB Output is correct
3 Incorrect 917 ms 2384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 921 ms 2384 KB Output is correct
2 Incorrect 959 ms 2472 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 971 ms 2432 KB Output is correct
2 Incorrect 937 ms 2324 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 952 ms 2436 KB Output is correct
2 Incorrect 882 ms 2344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 926 ms 2452 KB Output is correct
2 Incorrect 963 ms 2536 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 967 ms 2432 KB Output is correct
2 Correct 935 ms 2436 KB Output is correct
3 Incorrect 969 ms 2468 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 968 ms 2540 KB Output is correct
2 Incorrect 922 ms 2444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 999 ms 2432 KB Output is correct
2 Incorrect 982 ms 2532 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 999 ms 2476 KB Output is correct
2 Correct 971 ms 2480 KB Output is correct
3 Incorrect 981 ms 2472 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 990 ms 2472 KB Output is correct
2 Incorrect 972 ms 2528 KB Output isn't correct
3 Halted 0 ms 0 KB -