結果

問題 No.1211 円環はお断り
ユーザー e869120e869120
提出日時 2021-02-26 09:22:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,209 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 69,696 KB
実行使用メモリ 43,644 KB
最終ジャッジ日時 2024-04-09 22:37:34
合計ジャッジ時間 14,865 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 WA -
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 340 ms
24,584 KB
testcase_14 AC 416 ms
31,000 KB
testcase_15 AC 423 ms
30,256 KB
testcase_16 AC 827 ms
41,180 KB
testcase_17 AC 40 ms
9,088 KB
testcase_18 AC 384 ms
28,124 KB
testcase_19 AC 47 ms
9,592 KB
testcase_20 AC 56 ms
10,648 KB
testcase_21 AC 55 ms
10,180 KB
testcase_22 AC 341 ms
25,736 KB
testcase_23 AC 392 ms
29,452 KB
testcase_24 AC 223 ms
19,724 KB
testcase_25 AC 7 ms
6,940 KB
testcase_26 AC 486 ms
32,624 KB
testcase_27 AC 225 ms
18,824 KB
testcase_28 AC 494 ms
32,500 KB
testcase_29 AC 388 ms
27,148 KB
testcase_30 AC 557 ms
34,940 KB
testcase_31 AC 193 ms
18,264 KB
testcase_32 AC 721 ms
38,512 KB
testcase_33 AC 906 ms
43,456 KB
testcase_34 AC 905 ms
43,180 KB
testcase_35 AC 884 ms
42,872 KB
testcase_36 AC 905 ms
42,796 KB
testcase_37 AC 922 ms
41,860 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 3 ms
6,940 KB
testcase_42 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

long long N, K;
long long A[1 << 18], B[1 << 18];
long long par[1 << 18][22];
long long maxval = 0;
bool used[22];

bool solve(long long border) {
	int pos1 = 0;
	for (int i = 0; i <= 2 * N; i++) {
		while (pos1 < 2 * N && B[i] + border > B[pos1]) pos1++;
		par[i][0] = pos1;
	}
	for (int i = 0; i < maxval; i++) {
		for (int j = 0; j <= 2 * N; j++) par[j][i + 1] = par[par[j][i]][i];
	}

	for (int i = 0; i < N; i++) {
		int cx = i;
		for (int j = maxval; j >= 0; j--) {
			if (used[j] == true) cx = par[cx][j];
		}
		if (cx <= i + N) return true;
	}
	return false;
}

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = N; i <= 2 * N; i++) A[i] = A[i - N];
	for (int i = 0; i <= 2 * N; i++) B[i + 1] = B[i] + A[i];
	for (int i = 0; i < 22; i++) {
		if ((K / (1LL << i)) % 2 == 1) { used[i] = true; maxval = i; }
	}

	long long cl = 0, cr = B[N] / K, cm, maxn = 0, cnt = 0;
	for (int i = 0; i < 53; i++) {
		if (cr - cl <= 2) cnt++;
		if (cnt >= 4) break;
		cm = (cl + cr) / 2LL;
		bool I = solve(cm);
		if (I == true) { maxn = max(maxn, cm); cl = cm; }
		else { cr = cm; }
	}
	cout << maxn << endl;
	return 0;
}
0