Submission #144093

# Submission time Handle Problem Language Result Execution time Memory
144093 2019-08-16T03:23:34 Z liwi Akvizna (COCI19_akvizna) C++11
130 / 130
88 ms 2428 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define MOD2 1190492669
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 100005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

mt19937 g1(time(0));

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int N,K,dq[MAXN],l,r;
pair<double,int> dp[MAXN];

inline double inter(int j, int k){
	double m1 = dp[j].first, b1 = -j;
	double m2 = dp[k].first, b2 = -k;
	return (b2-b1)/(m1-m2);
}

inline int getGroups(double C){
	l = 1, r = 1, dq[1] = 0;
	for(int i=1; i<=N; i++){
		while(r-l >= 1 && dp[dq[l]].first*i-dq[l] <= dp[dq[l+1]].first*i-dq[l+1]) l++;
		dp[i].first = (dp[dq[l]].first*i-dq[l])/i+1-C;
		dp[i].second = dp[dq[l]].second+1;
		while(r-l >= 1 && inter(dq[r-1],i) <= inter(dq[r-1],dq[r])) r--;
		dq[++r] = i;
	}
	return dp[N].second;
}

int main(){
	scanf("%d %d",&N,&K);
	double low = 0, high = 20, ans = 0;
	while(high-low >= 1e-15){
		double mid = (low+high)/2;
		int g = getGroups(mid);
		if(g <= K){
			ans = mid;
			high = mid-1e-15;
		}else low = mid+1e-15;
	}
	getGroups(ans);
	double res = dp[N].first+ans*K;
	printf("%.8f\n",res);
}
/*
2 1
ans=1.5
 */

Compilation message

akvizna.cpp: In function 'int main()':
akvizna.cpp:69:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&N,&K);
  ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 2216 KB Output is correct
2 Correct 82 ms 2224 KB Output is correct
3 Correct 78 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 2164 KB Output is correct
2 Correct 85 ms 2280 KB Output is correct
3 Correct 82 ms 2300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 2168 KB Output is correct
2 Correct 86 ms 2348 KB Output is correct
3 Correct 85 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 2168 KB Output is correct
2 Correct 83 ms 2168 KB Output is correct
3 Correct 80 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 2168 KB Output is correct
2 Correct 85 ms 2296 KB Output is correct
3 Correct 81 ms 2244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 2424 KB Output is correct
2 Correct 82 ms 2168 KB Output is correct
3 Correct 81 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 2296 KB Output is correct
2 Correct 78 ms 2152 KB Output is correct
3 Correct 79 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 2188 KB Output is correct
2 Correct 85 ms 2312 KB Output is correct
3 Correct 79 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 2344 KB Output is correct
2 Correct 83 ms 2296 KB Output is correct
3 Correct 85 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 2296 KB Output is correct
2 Correct 81 ms 2168 KB Output is correct
3 Correct 85 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 2356 KB Output is correct
2 Correct 86 ms 2312 KB Output is correct
3 Correct 85 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 2340 KB Output is correct
2 Correct 85 ms 2352 KB Output is correct
3 Correct 85 ms 2316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 2424 KB Output is correct
2 Correct 85 ms 2312 KB Output is correct
3 Correct 87 ms 2428 KB Output is correct