結果

問題 No.576 E869120 and Rings
ユーザー WA_TLEWA_TLE
提出日時 2017-10-13 22:43:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 329 ms / 1,500 ms
コード長 1,974 bytes
コンパイル時間 1,420 ms
コンパイル使用メモリ 137,432 KB
実行使用メモリ 19,436 KB
最終ジャッジ日時 2023-08-11 00:27:13
合計ジャッジ時間 7,485 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 279 ms
15,444 KB
testcase_01 AC 240 ms
15,744 KB
testcase_02 AC 312 ms
15,432 KB
testcase_03 AC 329 ms
15,496 KB
testcase_04 AC 276 ms
15,652 KB
testcase_05 AC 276 ms
15,496 KB
testcase_06 AC 274 ms
15,528 KB
testcase_07 AC 318 ms
15,440 KB
testcase_08 AC 203 ms
15,544 KB
testcase_09 AC 188 ms
15,796 KB
testcase_10 AC 201 ms
15,680 KB
testcase_11 AC 165 ms
15,504 KB
testcase_12 AC 177 ms
15,588 KB
testcase_13 AC 146 ms
15,744 KB
testcase_14 AC 191 ms
15,588 KB
testcase_15 AC 48 ms
15,452 KB
testcase_16 AC 147 ms
19,436 KB
testcase_17 AC 159 ms
15,444 KB
testcase_18 AC 174 ms
15,496 KB
testcase_19 AC 173 ms
15,620 KB
testcase_20 AC 145 ms
15,496 KB
testcase_21 AC 176 ms
15,576 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<-1<<endl;return 0
//ios::sync_with_stdio(false);
//<< setprecision(5)
const int mod=1000000007;
const long double big=1e7+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
bool solve(int n,int k,const vector<int>&rui,double gen){
	int i;
	vector<double>rai(2*n+1);
	for(i=0;i<=2*n;i++){rai[i]=rui[i]-(gen*i);}
	deque<pair<double,int>>slide;//スラショ
	for(i=k;i<=2*n;i++){
		while(slide.size()>0&&rai[i-k]<=slide.back().fir){slide.pob();}
		slide.pub(mp(rai[i-k],i-k));
		if(slide.front().sec<i-n){slide.pof();}
		if(rai[i]-slide.front().fir>=0){return true;}
	}
	return false;
}
int main(void){
	ios::sync_with_stdio(false);
	int i,n,k;cin>>n>>k;
	vector<int>rui(2*n+1);//累積WA
	string str;cin>>str;
	for(i=0;i<n;i++){rui[i+1]=rui[i]+str[i]-'0';}
	for(i=n;i<2*n;i++){rui[i+1]=rui[i]+str[i-n]-'0';}
	double bmax=1,bmin=0;
	for(int h=0;h<25;h++){
		double gen=(bmax+bmin)/2;
		if(solve(n,k,rui,gen)){bmin=gen;}
		else{bmax=gen;}
	}
	cout<<setprecision(15)<<(bmax+bmin)/2<<endl;
	return 0;
}
0