結果

問題 No.576 E869120 and Rings
ユーザー ryoissyryoissy
提出日時 2017-10-14 17:34:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 628 ms / 1,500 ms
コード長 816 bytes
コンパイル時間 1,480 ms
コンパイル使用メモリ 164,448 KB
実行使用メモリ 16,236 KB
最終ジャッジ日時 2024-04-28 19:36:36
合計ジャッジ時間 12,901 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 556 ms
12,344 KB
testcase_01 AC 517 ms
12,432 KB
testcase_02 AC 620 ms
12,392 KB
testcase_03 AC 628 ms
12,372 KB
testcase_04 AC 551 ms
12,392 KB
testcase_05 AC 554 ms
12,432 KB
testcase_06 AC 516 ms
12,320 KB
testcase_07 AC 619 ms
12,384 KB
testcase_08 AC 425 ms
12,388 KB
testcase_09 AC 386 ms
12,560 KB
testcase_10 AC 430 ms
12,664 KB
testcase_11 AC 366 ms
12,288 KB
testcase_12 AC 359 ms
12,292 KB
testcase_13 AC 317 ms
12,568 KB
testcase_14 AC 398 ms
12,360 KB
testcase_15 AC 162 ms
12,208 KB
testcase_16 AC 346 ms
16,236 KB
testcase_17 AC 341 ms
12,364 KB
testcase_18 AC 370 ms
12,352 KB
testcase_19 AC 369 ms
12,224 KB
testcase_20 AC 317 ms
12,332 KB
testcase_21 AC 375 ms
12,332 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:35:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |         scanf("%d%d",&n,&k);
      |         ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define MOD 1000000007LL
#define EPS 1e-10
using namespace std;
typedef long long ll;
typedef pair<double,int> P;

int n,k;
string str;
double sum[1000001];

bool C(double vv){
	for(int i=0;i<str.size();i++){
		sum[i+1]=sum[i]-vv;
		if(str[i]=='1')sum[i+1]+=1.0;
	}
	deque<P> mx;
	for(int i=k;i<=str.size();i++){
		while(mx.size()){
			if(mx[0].second<=i-n){
				mx.pop_front();
			}else break;
		}
		while(mx.size()){
			if(mx.back().first>sum[i-k])mx.pop_back();
			else break;
		}
		mx.push_back(P(sum[i-k],i-k));
		if(mx.size() && sum[i]-mx[0].first>0.0)return true;
	}
	return false;
}

int main(void){
	scanf("%d%d",&n,&k);
	cin >> str;
	str+=str;
	double l=0.0,r=1.0;
	for(int i=0;i<30;i++){
		double mid=(l+r)/2;
		if(C(mid))l=mid;
		else r=mid;
	}
	printf("%.10f\n",l);
	return 0;
}
0