QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#736319#9540. Double 11ucup-team087TL 3914ms11224kbC++2318.8kb2024-11-12 09:51:072024-11-12 09:51:08

Judging History

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

  • [2024-11-12 09:51:08]
  • 评测
  • 测评结果:TL
  • 用时:3914ms
  • 内存:11224kb
  • [2024-11-12 09:51:07]
  • 提交

answer

#ifndef LOCAL
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#endif
#include <xmmintrin.h>

#include <bits/stdc++.h>
using namespace std;

using ll=long long;
#define int ll

bool dbg=false;

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;
using vvi=vc<vc<int>>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

#define mp make_pair
#define mt make_tuple
#define one(x) memset(x,-1,sizeof(x))
#define zero(x) memset(x,0,sizeof(x))
#ifdef LOCAL
void dmpr(ostream&os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ";
	dmpr(os,args...);
}
#define dmp2(...) dmpr(cerr,__LINE__,##__VA_ARGS__)
#else
#define dmp2(...) void(0)
#endif

using uint=unsigned;
using ull=unsigned long long;

template<class t,size_t n>
ostream& operator<<(ostream&os,const array<t,n>&a){
	return os<<vc<t>(all(a));
}

ll rand_int(ll l, ll r) { //[l, r]
	//#ifdef LOCAL
	static mt19937_64 gen;
	/*#else
	static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
	#endif*/
	return uniform_int_distribution<ll>(l, r)(gen);
}

ll rand_int(ll k){ //[0,k)
	return rand_int(0,k-1);
}
string rand_string(int n,char lw,char up){
	string s(n,'?');
	rep(i,n)s[i]=rand_int(lw,up);
	return s;
}

int current_run_id,run_batch_size=1000;
int calc_random_limit(){
	return current_run_id/run_batch_size+1;
}
template<class t>
void generate_single(t&a){
	a=rand_int(1,calc_random_limit());
}
void generate_single(string&a){
	int n;generate_single(n);
	a=rand_string(n,'a','b');
}
template<class t,class u>
void generate_single(pair<t,u>&a){
	generate_single(a.a);
	generate_single(a.b);
}
//https://trap.jp/post/1224/
template<class... Args>
void input(Args&... a){
	if(dbg){
		(generate_single(a),...);
	}else{
		#ifdef USE_FAST_IO
		sc.read(a...);
		#else
		(cin >> ... >> a);
		#endif
	}
}
#define INT(...) int __VA_ARGS__;input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;input(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;input(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;input(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;input(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;input(__VA_ARGS__)
#define overload3(a,b,c,d,...) d
#define VI2(name,size) vi name(size);rep(i_##name,size)input(name[i_##name]);
#define VI3(name,size,offset) vi name(size);rep(i_##name,size)input(name[i_##name]),name[i_##name]+=offset;
#define VI(...) overload3(__VA_ARGS__,VI3,VI2)(__VA_ARGS__)
#define VPI(name,size) vc<pi> name(size);rep(i_##name,size)input(name[i_##name]);
#define VVI(name,sizeN,sizeM) vvi name(sizeN,vi(sizeM));\
rep(i_##name,sizeN)rep(j_##name,sizeM)input(name[i_##name][j_##name]);
#define VS(name,size) vc<string> name(size);rep(i_##name,size)input(name[i_##name]);

#define overload5(a,b,c,d,e,f,...) f
#define VVC4(type,name,sizeN,sizeM) vvc<type> name(sizeN,vc<type>(sizeM));
#define VVC5(type,name,sizeN,sizeM,ini) vvc<type> name(sizeN,vc<type>(sizeM,ini));
#define VVC(...) overload5(__VA_ARGS__,VVC5,VVC4)(__VA_ARGS__)

template<class T>
T vvvc(T v){
	return v;
}

template<class T,class...Args>
auto vvvc(int n,T v,Args...args){
	return vector(n,vvvc(v,args...));
}

template<int i,class T>
void print_tuple(ostream&,const T&){
}

template<int i,class T,class H,class ...Args>
void print_tuple(ostream&os,const T&t){
	if(i)os<<",";
	os<<get<i>(t);
	print_tuple<i+1,T,Args...>(os,t);
}

template<class ...Args>
ostream& operator<<(ostream&os,const tuple<Args...>&t){
	os<<"{";
	print_tuple<0,tuple<Args...>,Args...>(os,t);
	return os<<"}";
}

void printsuc(int suc){
	#ifdef USE_FAST_IO
		if(suc==1)pr.write('\n');
		if(suc==2)pr.write(' ');
	#else
		if(suc==1){
			if(dbg)cout<<endl;
			else{
				#ifdef LOCAL
				cout<<endl;
				#else
				cout<<"\n";
				#endif
			}
		}
		if(suc==2)
			cout<<" ";
	#endif
}

template<class t>
void print_single(t x,int suc=1){
	#ifdef USE_FAST_IO
	pr.write(x);
	#else
	cout<<x;
	#endif
	printsuc(suc);
}

template<class t,class u>
void print_single(const pair<t,u>&p,int suc=1){
	print_single(p.a,2);
	print_single(p.b,suc);
}

template<class T>
void print_single(const vector<T>&v,int suc=1){
	rep(i,v.size())
		print_single(v[i],i==int(v.size())-1?3:2);
	printsuc(suc);
}

template<class T,size_t N>
void print_single(const array<T,N>&v,int suc=1){
	rep(i,N)
		print_single(v[i],i==int(N)-1?3:2);
	printsuc(suc);
}

template<class T>
void print(const T&t){
	print_single(t);
}

template<class T,class ...Args>
void print(const T&t,const Args&...args){
	print_single(t,2);
	print(args...);
}

template<class T>
void printvv(const vvc<T>&vs){
	for(const auto&row:vs)print(row);
}

string readString(){
	string s;
	cin>>s;
	return s;
}

template<class T>
T sq(const T& t){
	return t*t;
}

void YES(bool ex=true){
	cout<<"YES\n";
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void NO(bool ex=true){
	cout<<"NO\n";
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void Yes(bool ex=true){
	cout<<"Yes\n";
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void No(bool ex=true){
	cout<<"No\n";
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
//#define CAPITAL
/*
void yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<"\n";
	#else
	cout<<"Yes"<<"\n";
	#endif
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void no(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<"\n";
	#else
	cout<<"No"<<"\n";
	#endif
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}*/
void possible(bool ex=true){
	#ifdef CAPITAL
	cout<<"POSSIBLE"<<"\n";
	#else
	cout<<"Possible"<<"\n";
	#endif
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void impossible(bool ex=true){
	#ifdef CAPITAL
	cout<<"IMPOSSIBLE"<<"\n";
	#else
	cout<<"Impossible"<<"\n";
	#endif
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}

constexpr ll ten(int n){
	return n==0?1:ten(n-1)*10;
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

int topbit(signed t){
	return t==0?-1:31-__builtin_clz(t);
}
int topbit(ll t){
	return t==0?-1:63-__builtin_clzll(t);
}
int topbit(ull t){
	return t==0?-1:63-__builtin_clzll(t);
}
int botbit(signed a){
	return a==0?32:__builtin_ctz(a);
}
int botbit(ll a){
	return a==0?64:__builtin_ctzll(a);
}
int botbit(ull a){
	return a==0?64:__builtin_ctzll(a);
}
int popcount(signed t){
	return __builtin_popcount(t);
}
int popcount(ll t){
	return __builtin_popcountll(t);
}
int popcount(ull t){
	return __builtin_popcountll(t);
}
int bitparity(ll t){
	return __builtin_parityll(t);
}
bool ispow2(int i){
	return i&&(i&-i)==i;
}
ll mask(int i){
	return (ll(1)<<i)-1;
}
ull umask(int i){
	return (ull(1)<<i)-1;
}
ll minp2(ll n){
	if(n<=1)return 1;
	else return ll(1)<<(topbit(n-1)+1);
}

bool inc(int a,int b,int c){
	return a<=b&&b<=c;
}

template<class S> void mkuni(S&v){
	sort(all(v));
	v.erase(unique(all(v)),v.ed);
}

template<class t> bool isuni(vc<t> v){
	int s=si(v);
	mkuni(v);
	return si(v)==s;
}

template<class t>
void myshuffle(vc<t>&a){
	rep(i,si(a))swap(a[i],a[rand_int(0,i)]);
}

template<class S,class u>
int lwb(const S&v,const u&a){
	return lower_bound(all(v),a)-v.bg;
}
template<class t,class u>
bool bis(const vc<t>&v,const u&a){
	return binary_search(all(v),a);
}

//VERIFY: yosupo
//KUPC2017J
//AOJDSL1A
//without rank
struct unionfind{
	vi p,s;
	int c;
	unionfind(int n):p(n,-1),s(n,1),c(n){}
	void clear(){
		fill(all(p),-1);
		fill(all(s),1);
		c=si(p);
	}
	int find(int a){
		return p[a]==-1?a:(p[a]=find(p[a]));
	}
	//set b to a child of a
	bool unite(int a,int b){
		a=find(a);
		b=find(b);
		if(a==b)return false;
		p[b]=a;
		s[a]+=s[b];
		c--;
		return true;
	}
	bool same(int a,int b){
		return find(a)==find(b);
	}
	int sz(int a){
		return s[find(a)];
	}
};

vvc<int> readGraph(int n,int m){
	vvc<int> g(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		//sc.read(a,b);
		a--;b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	return g;
}

vvc<int> rand_tree(int n){
	vvc<int> t(n);
	unionfind uf(n);
	while(uf.c>1){
		int a=rand_int(n);
		int b=rand_int(n);
		if(uf.unite(a,b)){
			t[a].pb(b);
			t[b].pb(a);
		}
	}
	return t;
}

vvc<int> readTree(int n){
	if(dbg){
		return rand_tree(n);
	}else{
		return readGraph(n,n-1);
	}
}

vi readRooted(int n){
	assert(!dbg);
	vi par(n,-1);
	rng(i,1,n){
		input(par[i]);
		par[i]--;
		assert(inc(0,par[i],i-1));
	}
	return par;
}

void printTree(const vvc<int> t){
	int n=si(t);
	int degsum=0;
	rep(i,n)degsum+=si(t[i]);
	if(degsum==n-1){
		//directed
		rep(i,si(t))for(auto j:t[i]){
			print(i+1,j+1);
		}
	}else if(degsum==2*(n-1)){
		//undirected
		rep(i,si(t))for(auto j:t[i])if(i<j){
			print(i+1,j+1);
		}
	}else{
		assert(false);
	}
}

template<class t>
vc<t> presum(const vc<t>&a){
	vc<t> s(si(a)+1);
	rep(i,si(a))s[i+1]=s[i]+a[i];
	return s;
}
vc<ll> presum(const vi&a){
	vc<ll> s(si(a)+1);
	rep(i,si(a))s[i+1]=s[i]+a[i];
	return s;
}
//BIT で数列を管理するときに使う (CF850C)
template<class t>
vc<t> predif(vc<t> a){
	gnr(i,1,si(a))a[i]-=a[i-1];
	return a;
}
template<class t>
vvc<ll> imos(const vvc<t>&a){
	int n=si(a),m=si(a[0]);
	vvc<ll> b(n+1,vc<ll>(m+1));
	rep(i,n)rep(j,m)
		b[i+1][j+1]=b[i+1][j]+b[i][j+1]-b[i][j]+a[i][j];
	return b;
}

//verify してないや
void transvvc(int&n,int&m){
	swap(n,m);
}
template<class t,class... Args>
void transvvc(int&n,int&m,vvc<t>&a,Args&...args){
	assert(si(a)==n);
	vvc<t> b(m,vi(n));
	rep(i,n){
		assert(si(a[i])==m);
		rep(j,m)b[j][i]=a[i][j];
	}
	a.swap(b);
	transvvc(n,m,args...);
}
//CF854E
void rotvvc(int&n,int&m){
	swap(n,m);
}
template<class t,class... Args>
void rotvvc(int&n,int&m,vvc<t>&a,Args&...args){
	assert(si(a)==n);
	vvc<t> b(m,vi(n));
	rep(i,n){
		assert(si(a[i])==m);
		rep(j,m)b[m-1-j][i]=a[i][j];
	}
	a.swap(b);
	rotvvc(n,m,args...);
}

//ソートして i 番目が idx[i]
//CF850C
template<class t>
vi sortidx(const vc<t>&a){
	int n=si(a);
	vi idx(n);iota(all(idx),0);
	sort(all(idx),[&](int i,int j){return a[i]<a[j];});
	return idx;
}
//vs[i]=a[idx[i]]
//例えば sortidx で得た idx を使えば単にソート列になって返ってくる
//CF850C
template<class t>
vc<t> a_idx(const vc<t>&a,const vi&idx){
	int n=si(a);
	assert(si(idx)==n);
	vc<t> vs(n);
	rep(i,n)vs[i]=a[idx[i]];
	return vs;
}
//CF850C
vi invperm(const vi&p){
	int n=si(p);
	vi q(n);
	rep(i,n)q[p[i]]=i;
	return q;
}

template<class t,class s=t>
s SUM(const vc<t>&a){
	return accumulate(all(a),s(0));
}
template<class t,size_t K,class s=t>
s SUM(const array<t,K>&a){
	return accumulate(all(a),s(0));
}

template<class t>
t MAX(const vc<t>&a){
	return *max_element(all(a));
}

template<class t>
pair<t,int> MAXi(const vc<t>&a){
	auto itr=max_element(all(a));
	return mp(*itr,itr-a.bg);
}

template<class A>
auto MIN(const A&a){
	return *min_element(all(a));
}

template<class t>
pair<t,int> MINi(const vc<t>&a){
	auto itr=min_element(all(a));
	return mp(*itr,itr-a.bg);
}

vi vid(int n){
	vi res(n);iota(all(res),0);
	return res;
}

template<class S>
void soin(S&s){
	sort(all(s));
}

template<class S,class F>
void soin(S&s,F&&f){
	sort(all(s),forward<F>(f));
}

template<class S>
S soout(S s){
	soin(s);
	return s;
}

template<class S>
void rein(S&s){
	reverse(all(s));
}

template<class S>
S reout(S s){
	rein(s);
	return s;
}

template<class t,class u>
pair<t,u>&operator+=(pair<t,u>&a,pair<t,u> b){
	a.a+=b.a;a.b+=b.b;return a;}
template<class t,class u>
pair<t,u>&operator-=(pair<t,u>&a,pair<t,u> b){
	a.a-=b.a;a.b-=b.b;return a;}
template<class t,class u>
pair<t,u> operator+(pair<t,u> a,pair<t,u> b){return mp(a.a+b.a,a.b+b.b);}
template<class t,class u>
pair<t,u> operator-(pair<t,u> a,pair<t,u> b){return mp(a.a-b.a,a.b-b.b);}
template<class t,class u,class v>
pair<t,u>&operator*=(pair<t,u>&a,v b){
	a.a*=b;a.b*=b;return a;}
template<class t,class u,class v>
pair<t,u> operator*(pair<t,u> a,v b){return a*=b;}
template<class t,class u>
pair<t,u> operator-(pair<t,u> a){return mp(-a.a,-a.b);}
namespace std{
template<class t,class u>
istream&operator>>(istream&is,pair<t,u>&a){
	return is>>a.a>>a.b;
}
}

template<class t>
t gpp(vc<t>&vs){
	assert(si(vs));
	t res=move(vs.back());
	vs.pop_back();
	return res;
}

template<class t,class u>
void pb(vc<t>&a,const vc<u>&b){
	a.insert(a.ed,all(b));
}

template<class t,class...Args>
vc<t> cat(vc<t> a,Args&&...b){
	(pb(a,forward<Args>(b)),...);
	return a;
}

template<class t,class u>
vc<t>& operator+=(vc<t>&a,u x){
	for(auto&v:a)v+=x;
	return a;
}

template<class t,class u>
vc<t> operator+(vc<t> a,u x){
	return a+=x;
}

template<class t>
vc<t>& operator+=(vc<t>&a,const vc<t>&b){
	a.resize(max(si(a),si(b)));
	rep(i,si(b))a[i]+=b[i];
	return a;
}

template<class t>
vc<t> operator+(const vc<t>&a,const vc<t>&b){
	vc<t> c(max(si(a),si(b)));
	rep(i,si(a))c[i]+=a[i];
	rep(i,si(b))c[i]+=b[i];
	return c;
}

template<class t,class u>
vc<t>& operator-=(vc<t>&a,u x){
	for(auto&v:a)v-=x;
	return a;
}
template<class t,class u>
vc<t> operator-(vc<t> a,u x){
	return a-=x;
}
template<class t>
vc<t>& operator-=(vc<t>&a,const vc<t>&b){
	a.resize(max(si(a),si(b)));
	rep(i,si(b))a[i]-=b[i];
	return a;
}
/*
template<class t>
vc<t> operator-(const vc<t>&a,const vc<t>&b){
	vc<t> c(max(si(a),si(b)));
	rep(i,si(a))c[i]+=a[i];
	rep(i,si(b))c[i]-=b[i];
	return c;
}
*/
template<class t,class u>
vc<t>& operator*=(vc<t>&a,u x){
	for(auto&v:a)v*=x;
	return a;
}
template<class t,class u>
vc<t> operator*(vc<t> a,u x){
	return a*=x;
}

template<class t,class u>
vc<t>& operator/=(vc<t>&a,u x){
	for(auto&v:a)v/=x;
	return a;
}
template<class t,class u>
vc<t> operator/(vc<t> a,u x){
	return a/=x;
}

template<class t>
vc<t>& operator<<=(vc<t>&a,int k){
	assert(k>=0);
	a.insert(a.bg,k,t(0));
	return a;
}
template<class t>
vc<t> operator<<(vc<t> a,int k){
	return a<<=k;
}

template<class t>
vc<t>& operator>>=(vc<t>&a,int k){
	if(si(a)<=k)a.clear();
	else a.erase(a.bg,a.bg+k);
	return a;
}
template<class t>
vc<t> operator>>(vc<t> a,int k){
	return a>>=k;
}

template<class t,class u>
void remval(vc<t>&a,const u&v){
	a.erase(remove(all(a),v),a.ed);
}
//消した要素の個数を返してくれる
//UCUP 2-8-F
template<class t,class F>
int remif(vc<t>&a,F f){
	auto itr=remove_if(all(a),f);
	int res=a.ed-itr;
	a.erase(itr,a.ed);
	return res;
}
template<class t>
void rempos(vc<t>&a,int i){
	assert(inc(0,i,si(a)-1));
	a.erase(a.bg+i);
}

template<class VS,class u>
void fila(VS&vs,const u&a){
	fill(all(vs),a);
}

template<class t,class u>
int findid(const vc<t>&vs,const u&a){
	auto itr=find(all(vs),a);
	if(itr==vs.ed)return -1;
	else return itr-vs.bg;
}

template<class t>
void rtt(vc<t>&vs,int i){
	rotate(vs.bg,vs.bg+i,vs.ed);
}

//Multiuni2023-8 C
//f(lw)=false,...,f(n-1)=false,f(n)=true,...,f(up)=true,
//のときに n を返す
template<class F>
int find_min_true(int lw,int up,F f){
	while(up-lw>1){
		const int mid=(lw+up)/2;
		if(f(mid))up=mid;
		else lw=mid;
	}
	return up;
}
//f(lw)=true,f(up)=false
template<class F>
int find_max_true(int lw,int up,F f){
	while(up-lw>1){
		const int mid=(lw+up)/2;
		if(f(mid))lw=mid;
		else up=mid;
	}
	return lw;
}

template<class t> using pqmin=priority_queue<t,vc<t>,greater<t>>;
template<class t> using pqmax=priority_queue<t>;
using T=tuple<int,int,int>;

//cost(i,j) が monge
//O(N log N) で DP する
//stress-tested
//https://noshi91.hatenablog.com/entry/2023/02/18/005856
//コストを求める部分が slide でできる.
template<class F>
auto&larsch(int n,F cost){
	assert(2<=n);
	using t=typename invoke_result<F,int,int>::type;
	static vc<t> res;res.resize(n);
	static vi pos;pos.resize(n);fill(all(pos),-1);
	auto upd=[&](int from,int to){
		t val=res[from]+cost(from,to);
		if(pos[to]==-1||res[to]>val){
			res[to]=val;
			pos[to]=from;
		}
	};
	auto dfs=[&](auto self,int l,int r)->void{
		if(r-l==1){
			if(l==0)res[0]=t{};
		}else{
			int m=(l+r)/2;
			//同じ lv でここだけみたら cost(i,j) の i,j が単調
			if(l)rng(i,max<int>(pos[l-1],0),pos[r-1]+1)upd(i,m-1);
			self(self,l,m);
			//同じ lv でここだけみたら cost(i,j) の i,j が単調
			rng(i,l,m)upd(i,r-1);
			self(self,m,r);
		}
	};
	dfs(dfs,0,n);
	return res;
}

//0->n-1 のジャンプ
//monge コストでちょうど k step でやれ,みたいな最小化問題 
//ans(step) が単調減少だとする(つまり小刻みであればあるほど嬉しい)
//max(ans(step))-max(ans(step)) の上界を dif で与えている
//stress-tested (define ll なし,復元もちゃんと確かめた)
using ld=double;
template<class F>
ld kstepmin(int n,int k,ld dif,F cost){
	assert(inc(1,k,n-1));
	ld lw=-1,up=dif+1,ans=infLL;
	rep(_,100){
		ld mid=(lw+up)/2;
		auto&dp=larsch(n,[&](int i,int j){
			return pair<ld,int>(cost(i,j)+mid,1);
		});
		if(dp[n-1].b<=k){
			up=mid;
			ans=dp[n-1].a-k*mid;
		}else lw=mid;
	}
	assert(ans<infLL);
	return ans;
}

void slv(){
	INT(n,m);
	VI(a,n);
	soin(a,greater<int>());
	
	ld ans=infLL;
	rep(_,1){
		vi b=presum(a);
		auto f=[&](int i,int j){
			return sqrtl((j-i)*(b[j]-b[i]));
		};
		chmin(ans,kstepmin(n+1,m,ten(18),f));
		rein(a);
	}
	
	print(ans);
}

signed main(signed argc,char*argv[]){
	if(argc>1&&strcmp(argv[1],"D")==0)dbg=true;
	_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
	
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	if(dbg){
		while(1){
			if(current_run_id%run_batch_size==0){
				cerr<<"Current Run "<<current_run_id<<endl;
			}
			slv();
			current_run_id++;
		}
	}else{
		//int t;cin>>t;rep(_,t)
		slv();
	}
}

詳細信息

Test #1:

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

input:

4 2
1 2 3 4

output:

6.19114712955711965492

result:

ok found '6.191147130', expected '6.191147130', error '0.000000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

10 3
1 2 3 4 5 6 7 8 9 10

output:

22.59162536651412978017

result:

ok found '22.591625367', expected '22.591625367', error '0.000000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3904kb

input:

1 1
1

output:

1.00000000000000000000

result:

ok found '1.000000000', expected '1.000000000', error '0.000000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

1 1
100000

output:

316.22776601683790431707

result:

ok found '316.227766017', expected '316.227766017', error '0.000000000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

7 1
10 47 53 9 83 33 15

output:

41.83300132670377990962

result:

ok found '41.833001327', expected '41.833001327', error '0.000000000'

Test #6:

score: 0
Accepted
time: 0ms
memory: 4008kb

input:

8 5
138 1702 119 1931 418 1170 840 1794

output:

233.90165455194355104140

result:

ok found '233.901654552', expected '233.901654552', error '0.000000000'

Test #7:

score: 0
Accepted
time: 1ms
memory: 3836kb

input:

58 1
888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983

output:

1355.26528768355910870014

result:

ok found '1355.265287684', expected '1355.265287684', error '0.000000000'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3940kb

input:

88 30
67117 31903 93080 85196 16438 97116 11907 72959 83651 41273 52873 81892 81468 51323 99992 58869 54258 7183 87358 90990 80596 41252 90769 82705 61434 8524 13575 10787 53950 96768 12062 34637 27806 70937 69653 28380 90236 3352 27537 3873 91006 89790 25369 91825 82734 5588 4539 74118 47098 84741 ...

output:

18791.47535409410193096846

result:

ok found '18791.475354094', expected '18791.475354094', error '0.000000000'

Test #9:

score: 0
Accepted
time: 4ms
memory: 3968kb

input:

987 59
5209 1618 7129 7700 893 6647 8231 3314 9844 1347 6789 2711 3968 7416 5864 9190 9564 8874 7357 2087 530 8754 7935 6772 3475 8206 2898 2717 9252 8686 6604 5188 7451 9977 9366 7618 6294 6454 3919 3232 8164 8403 8617 2191 5257 626 8554 1952 1727 4759 205 9453 3312 9387 4798 7774 7005 8892 3570 50...

output:

66075.50858705463178921491

result:

ok found '66075.508587055', expected '66075.508587055', error '0.000000000'

Test #10:

score: 0
Accepted
time: 2ms
memory: 4012kb

input:

572 529
48392 84311 16267 29255 52276 20511 75195 95522 64489 52229 74478 69766 41777 25148 59976 66512 62953 16779 69312 98832 96131 94700 46403 58028 12868 83503 80367 51036 63398 7509 55193 76715 29143 75925 89863 89244 5561 21242 9047 89763 78016 86274 11382 88520 72343 29729 70986 86600 43707 7...

output:

119849.32268175805802457035

result:

ok found '119849.322681758', expected '119849.322681758', error '0.000000000'

Test #11:

score: 0
Accepted
time: 25ms
memory: 3940kb

input:

6133 2231
2292 4026 3420 3246 5243 41 4223 468 682 5008 1497 584 1573 7049 5848 4129 5555 9957 9311 7225 6065 9498 3569 1695 717 1968 9690 7557 8700 9427 5142 371 8788 2260 9576 2674 4322 7448 5829 9123 982 7591 438 1590 9459 5982 5002 243 4144 4254 9585 9988 6745 3691 9602 2297 9518 1181 9814 1746 ...

output:

406852.36690047144657000899

result:

ok found '406852.366900471', expected '406852.366900471', error '0.000000000'

Test #12:

score: 0
Accepted
time: 32ms
memory: 4036kb

input:

8384 5123
19058 18998 87373 34122 75328 47694 7628 72373 15038 82392 99284 70202 49919 24589 3369 42325 8281 56682 20694 78018 67433 34318 26086 37124 18668 94430 78732 53794 58279 21730 60156 95172 58849 10021 70991 26522 88420 92248 63779 33077 16703 80111 94041 85804 3110 21282 12757 69593 53872 ...

output:

1764954.76112866890616714954

result:

ok found '1764954.761128669', expected '1764954.761128677', error '0.000000000'

Test #13:

score: 0
Accepted
time: 463ms
memory: 6740kb

input:

92842 83212
71466 9482 98728 78471 22915 2470 5999 53211 25994 3996 11349 30511 56448 17277 78308 18316 42069 38636 63127 26256 63985 57249 58305 64366 17839 28518 18980 95945 36316 6076 69530 96509 6940 6039 56048 41847 82118 41054 49670 95896 45891 74636 90736 75413 27251 87730 68344 66202 71879 5...

output:

19558873.68885633721947669983

result:

ok found '19558873.688856337', expected '19558873.688863300', error '0.000000000'

Test #14:

score: 0
Accepted
time: 675ms
memory: 6836kb

input:

93773 73078
12212 18977 10701 17909 16643 1406 15608 19767 11321 4708 10418 5834 10141 18240 12668 2694 11528 16150 8201 793 9736 15133 17474 6052 830 8574 1473 6393 11680 9784 16406 3428 10520 6431 7941 3167 17474 16569 19046 9595 7858 12512 7204 414 13548 7490 9887 9184 4298 1124 8330 749 12122 14...

output:

8833985.13989353552460670471

result:

ok found '8833985.139893536', expected '8833985.139919622', error '0.000000000'

Test #15:

score: 0
Accepted
time: 504ms
memory: 6816kb

input:

93116 27259
19231 23827 31564 18589 37658 17067 9191 26550 24206 13382 31064 1668 35186 10253 21408 16584 23217 11706 6324 16856 1642 28253 25916 39965 9455 35610 19925 15446 23558 36649 20624 35732 32683 33877 35121 26492 33868 35902 3312 18504 12747 31575 827 16198 22080 8616 16114 11479 1973 3457...

output:

12413208.32707370258867740631

result:

ok found '12413208.327073703', expected '12413208.327073758', error '0.000000000'

Test #16:

score: 0
Accepted
time: 377ms
memory: 5792kb

input:

65921 2855
20842 45572 19723 30757 45969 18135 30070 21845 37090 9353 43198 30206 34823 2265 17444 873 3418 23069 21343 37110 34764 57182 14358 46583 33887 35351 2569 23283 58540 16218 14441 20740 19039 38219 56892 41305 10261 59427 50682 24309 37637 26446 14450 19278 6420 9741 22342 33775 32351 802...

output:

10762858.11282143741846084595

result:

ok found '10762858.112821437', expected '10762858.112821424', error '0.000000000'

Test #17:

score: 0
Accepted
time: 257ms
memory: 5344kb

input:

51522 31326
39349 67318 23689 58733 39687 26500 10949 48629 17271 5323 48036 50232 34460 66982 78888 57867 15107 34433 12169 33173 75182 30302 50097 36305 18320 75092 65214 79632 63123 75786 38659 5749 68498 18369 24071 64631 59359 18760 27652 45922 69822 61317 75369 39254 14952 10867 37081 64582 55...

output:

9723573.24602977186441421509

result:

ok found '9723573.246029772', expected '9723573.246029738', error '0.000000000'

Test #18:

score: 0
Accepted
time: 276ms
memory: 5436kb

input:

56053 42277
44411 63391 89865 72721 53843 682 14093 38372 3169 41756 82551 28149 31782 71836 19611 34812 18856 72210 69678 67556 59039 36318 44318 35358 85736 5362 64440 45710 1222 39219 67664 73453 3228 55740 31308 7845 75460 36874 46537 50376 58011 3889 4885 83498 25570 821 87491 47826 2719 12994 ...

output:

11198792.69845383241772651672

result:

ok found '11198792.698453832', expected '11198792.698453829', error '0.000000000'

Test #19:

score: 0
Accepted
time: 49ms
memory: 3968kb

input:

10687 1668
3046 53154 91555 70369 35072 15080 9869 99592 62955 62818 3738 33628 46863 21042 26955 49834 6856 3243 6710 72239 24998 91735 93252 56350 61643 4017 22164 55902 95984 89163 14423 82410 24767 26122 89106 92303 22874 50437 24863 12593 40947 70729 13996 31622 46354 1272 78874 62489 56915 511...

output:

2255523.48281871527433395386

result:

ok found '2255523.482818715', expected '2255523.482818719', error '0.000000000'

Test #20:

score: 0
Accepted
time: 82ms
memory: 4060kb

input:

18491 14176
87034 87309 95737 63513 94815 15170 3598 37211 10872 34733 51296 31647 86912 8982 7437 57343 48536 17100 16918 66460 49859 6047 93123 42873 47721 46308 98300 90715 23288 91189 11794 36943 49470 66414 74516 58084 90033 84433 85946 26700 65191 4451 75166 44736 98110 91661 86206 22681 16853...

output:

3888512.05915066180750727654

result:

ok found '3888512.059150662', expected '3888512.059150661', error '0.000000000'

Test #21:

score: 0
Accepted
time: 175ms
memory: 4452kb

input:

34254 8157
71022 54169 99920 91248 54559 47964 38544 7534 82981 82455 55750 29665 83857 5435 22510 64853 22919 30957 59830 27977 66208 53064 92993 86291 25288 31704 41733 17016 60992 58623 41868 56885 15389 82515 68439 32377 24487 42622 3926 6216 24027 95069 95121 57849 84458 71650 52322 15577 44088...

output:

7195750.04214484803378582001

result:

ok found '7195750.042144848', expected '7195750.042144855', error '0.000000000'

Test #22:

score: 0
Accepted
time: 235ms
memory: 4936kb

input:

48030 28734
87714 88324 4102 84392 81599 48055 32273 2049 30898 30178 3309 60387 23906 69184 46096 15466 64598 10222 70039 22199 23772 10480 92863 5517 35558 41291 17869 19125 55592 93353 71943 44122 72795 22808 53849 30862 83133 811 65010 96131 48271 85687 23588 70963 60406 18935 59655 8473 4026 43...

output:

10117497.09838476218283176422

result:

ok found '10117497.098384762', expected '10117497.098384907', error '0.000000000'

Test #23:

score: 0
Accepted
time: 243ms
memory: 5092kb

input:

45116 12480
38998 22480 8284 44832 17150 48145 34514 72372 78815 2092 7763 58405 20850 57124 93874 22975 38981 24079 88759 16420 48633 24792 68541 81639 54341 16286 61301 53937 58704 28082 2018 31360 62906 71613 71964 63939 50292 34807 58797 75647 72515 43601 76246 84077 79457 42028 58475 68665 3126...

output:

9528295.64064561948180198669

result:

ok found '9528295.640645619', expected '9528295.640645649', error '0.000000000'

Test #24:

score: 0
Accepted
time: 313ms
memory: 5528kb

input:

56563 5852
22986 89339 12467 5271 44190 56747 28243 66887 59436 15223 55321 13319 85091 20873 41651 30485 4852 37936 98967 77937 97686 82209 35708 68161 31907 25873 37438 56046 20600 95516 32093 18597 96121 11906 65886 38232 84746 92996 19881 89755 31351 34219 4713 97191 98509 89314 33103 61561 5849...

output:

11918743.60685941390693187714

result:

ok found '11918743.606859414', expected '11918743.606859455', error '0.000000000'

Test #25:

score: 0
Accepted
time: 223ms
memory: 4804kb

input:

40604 4266
6974 56198 16649 98415 36638 56837 30485 37210 7353 87137 27071 44041 57844 17325 22133 70698 79236 84497 41879 72158 22547 29225 35578 87387 17985 43972 80870 15051 91009 97542 29464 5835 53527 28006 51297 36717 19201 51185 80964 36566 55595 67941 57372 86112 41753 12407 31924 54457 1843...

output:

8546423.37744641490280628204

result:

ok found '8546423.377446415', expected '8546423.377446430', error '0.000000000'

Test #26:

score: 0
Accepted
time: 272ms
memory: 5352kb

input:

55318 38425
90962 90354 20831 58854 63677 24224 24214 31725 79463 34859 7333 42059 54789 81074 45719 54015 53619 98354 27896 99083 47408 19345 35448 30805 28256 53559 24302 17160 85609 64976 59539 68881 10934 68299 69411 2498 86359 85182 66240 83378 79839 58559 85839 31930 60805 59692 30744 23161 21...

output:

11659354.10822085291147232056

result:

ok found '11659354.108220853', expected '11659354.108220546', error '0.000000000'

Test #27:

score: 0
Accepted
time: 1998ms
memory: 11152kb

input:

200000 1234
15 714 103 881 808 595 505 281 451 187 555 889 276 415 335 227 613 937 149 954 82 632 855 765 134 134 245 675 83 168 955 785 143 290 750 373 25 504 115 47 368 550 792 522 356 745 337 120 91 388 284 283 198 260 181 565 145 708 91 673 86 26 89 463 683 328 798 692 39 660 213 263 697 232 270...

output:

4214040.17686986643821001053

result:

ok found '4214040.176869866', expected '4214040.176869883', error '0.000000000'

Test #28:

score: 0
Accepted
time: 852ms
memory: 11148kb

input:

200000 199999
10 7 5 1 4 3 5 2 1 9 4 2 8 9 4 2 1 1 10 4 5 3 10 9 2 10 5 7 3 8 10 2 7 8 3 2 2 8 4 6 3 5 6 4 1 3 6 8 10 5 10 6 3 9 7 7 5 2 5 5 8 10 8 8 10 3 3 3 2 8 8 8 7 4 6 7 6 4 4 8 7 10 7 5 7 8 7 9 10 9 3 4 7 2 6 7 3 4 8 1 10 8 10 10 9 7 7 7 9 3 6 5 5 2 9 7 5 9 10 6 2 5 8 5 8 6 8 3 9 4 3 2 1 9 9 4...

output:

449053.81111163459718227386

result:

ok found '449053.811111635', expected '449053.811111193', error '0.000000000'

Test #29:

score: 0
Accepted
time: 855ms
memory: 11220kb

input:

200000 200000
358 771 657 465 176 649 647 448 728 699 177 933 260 526 992 470 894 953 535 67 749 6 152 49 442 532 917 115 820 799 320 684 604 446 507 966 177 845 665 390 798 17 484 245 343 678 420 385 400 372 302 986 94 174 714 69 715 498 189 245 22 555 789 581 313 218 792 327 601 353 365 568 666 63...

output:

4222121.93000969849526882172

result:

ok found '4222121.930009698', expected '4222121.930008642', error '0.000000000'

Test #30:

score: 0
Accepted
time: 959ms
memory: 11096kb

input:

200000 200000
87338 73783 5523 51991 2881 68863 41883 44070 3441 34634 95748 88273 74444 60113 20629 22994 13258 95825 61397 99590 61030 26857 37043 41169 72575 53085 65727 47415 21721 75830 69038 55268 50746 56928 98969 81861 17837 48843 62334 78509 75970 45483 74046 80593 36396 24888 86046 76524 9...

output:

42177852.87774407863616943359

result:

ok found '42177852.877744079', expected '42177852.877710223', error '0.000000000'

Test #31:

score: 0
Accepted
time: 1245ms
memory: 10920kb

input:

200000 5698
82273 82167 30031 13695 19452 64050 68613 897 334 80715 14998 44711 28499 78542 13914 76158 78533 3286 14277 58166 81541 45757 14133 58390 60765 90835 10826 28045 71726 17165 9760 34757 97720 82390 89908 25061 40905 72791 45647 36498 34106 74512 22859 78545 83357 59834 44256 89374 25931 ...

output:

42175982.59780570864677429199

result:

ok found '42175982.597805709', expected '42175982.597805873', error '0.000000000'

Test #32:

score: 0
Accepted
time: 1132ms
memory: 11152kb

input:

200000 57033
49 95 72 8 70 13 12 59 1 39 53 79 49 64 46 94 13 30 54 69 98 2 39 7 87 4 91 12 88 10 6 15 32 95 22 66 63 18 94 1 33 25 89 6 52 58 91 40 68 53 49 58 38 37 83 78 8 19 5 53 53 26 12 4 76 85 78 16 92 42 46 64 74 24 42 77 53 11 28 82 95 47 94 82 62 47 38 66 64 60 12 28 25 3 23 60 84 8 75 87 ...

output:

32283131.19290679693222045898

result:

ok found '32283131.192906797', expected '32283131.201386724', error '0.000000000'

Test #33:

score: 0
Accepted
time: 3456ms
memory: 11152kb

input:

200000 192622
22 77 88 52 25 20 83 18 76 47 84 34 54 88 9 90 49 8 79 91 78 51 56 57 13 7 35 45 71 99 25 42 92 84 2 66 46 19 95 77 87 85 90 59 90 38 89 10 23 35 78 25 12 4 74 35 44 18 31 5 28 45 55 31 63 90 46 93 48 65 40 90 72 45 71 82 76 95 52 53 22 78 79 77 99 43 8 38 35 41 8 57 85 35 96 24 11 64 ...

output:

32283316.33463359624147415161

result:

ok found '32283316.334633596', expected '32283316.334659215', error '0.000000000'

Test #34:

score: 0
Accepted
time: 3914ms
memory: 11224kb

input:

200000 142088
88 24 73 53 86 93 28 44 44 13 84 36 9 30 70 80 80 45 51 97 14 85 16 21 24 60 88 78 56 60 39 23 33 7 60 93 32 85 97 34 4 35 10 66 92 29 64 31 53 35 88 74 40 60 73 82 90 1 43 87 6 67 83 35 89 95 47 14 20 15 11 24 27 82 24 59 42 74 96 50 73 61 26 79 13 59 29 21 4 70 49 42 79 81 67 18 15 4...

output:

32284074.53262465819716453552

result:

ok found '32284074.532624658', expected '32284074.532721698', error '0.000000000'

Test #35:

score: -100
Time Limit Exceeded

input:

200000 120274
25 80 33 47 43 55 92 10 3 85 41 52 58 37 12 80 50 67 14 48 50 9 95 67 67 12 93 63 34 27 93 73 68 27 56 83 94 59 7 78 42 46 29 74 6 98 80 86 52 71 27 97 56 10 48 80 74 23 32 81 28 25 96 95 35 77 84 76 77 97 96 97 95 78 83 48 74 23 1 58 85 61 13 63 31 98 18 67 45 78 19 20 86 33 56 72 3 1...

output:


result: