結果

問題 No.576 E869120 and Rings
ユーザー ふっぴーふっぴー
提出日時 2017-10-14 01:20:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,731 bytes
コンパイル時間 1,771 ms
コンパイル使用メモリ 172,912 KB
実行使用メモリ 10,708 KB
最終ジャッジ日時 2024-04-28 17:57:28
合計ジャッジ時間 3,322 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 22 ms
7,716 KB
testcase_09 WA -
testcase_10 AC 22 ms
7,864 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 22 ms
7,840 KB
testcase_14 AC 29 ms
10,708 KB
testcase_15 AC 13 ms
6,944 KB
testcase_16 AC 15 ms
6,940 KB
testcase_17 AC 28 ms
10,548 KB
testcase_18 AC 22 ms
8,096 KB
testcase_19 AC 22 ms
7,964 KB
testcase_20 AC 22 ms
7,840 KB
testcase_21 WA -
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 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
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	int n, k, i, j;
	cin >> n >> k;
	string s;
	cin >> s;
	for (i = n-1; i >= 0; i--) {
		if (s[i] == '0') {
			break;
		}
	}
	if (i == -1) {
		cout << 1 << endl;
		return 0;
	}
	s = s.substr(i, n - i) + s.substr(0, i);
	vi blue;
	int cnt = 0;
	for (i = 1; i < n; i++) {
		if (s[i] == '1') {
			cnt++;
		}
		else {
			blue.push_back(cnt);
			cnt = 0;
		}
	}
	blue.push_back(cnt);
	//cout << s << endl;
	//DEBUG_VEC(blue);
	//DEBUG_VEC(blue);
	int m = blue.size();
	vi sum(2 * m + 1);
	sum[0] = 0;
	for (i = 1; i <= 2 * m; i++) {
		sum[i] = sum[i - 1] + blue[(i-1)%m];
	}
	//DEBUG_VEC(sum);
	int left = 0, right = m;
	double ans = 0;
	while (left < right) {
		int mid = (left + right) / 2;
		int b = 0;
		if (mid == m) {
			ans = (double)sum[m] / n;
		}
		else {
			for (i = 0; i < m; i++) {
				b = max(b, sum[i + 1 + mid] - sum[i]);
			}
			if (b + mid >= k) {
				ans = (double)b / (b + mid);
				right = mid;
			}
			else {
				left = mid + 1;
			}
		}
	}
	Sp(ans);
}
0