結果

問題 No.1211 円環はお断り
ユーザー e869120e869120
提出日時 2021-02-26 09:19:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,951 ms / 2,000 ms
コード長 1,108 bytes
コンパイル時間 639 ms
コンパイル使用メモリ 68,988 KB
実行使用メモリ 43,668 KB
最終ジャッジ日時 2024-04-09 22:33:41
合計ジャッジ時間 9,688 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 724 ms
25,456 KB
testcase_14 AC 1,043 ms
30,572 KB
testcase_15 AC 1,038 ms
30,084 KB
testcase_16 AC 1,883 ms
41,124 KB
testcase_17 AC 105 ms
9,564 KB
testcase_18 AC 805 ms
28,924 KB
testcase_19 AC 106 ms
9,824 KB
testcase_20 AC 146 ms
10,824 KB
testcase_21 AC 138 ms
11,316 KB
testcase_22 AC 735 ms
26,728 KB
testcase_23 AC 867 ms
30,340 KB
testcase_24 AC 488 ms
18,556 KB
testcase_25 AC 15 ms
8,088 KB
testcase_26 AC 1,064 ms
32,940 KB
testcase_27 AC 488 ms
19,016 KB
testcase_28 AC 1,136 ms
32,616 KB
testcase_29 AC 853 ms
27,572 KB
testcase_30 AC 1,181 ms
35,536 KB
testcase_31 AC 560 ms
18,028 KB
testcase_32 AC 1,630 ms
38,580 KB
testcase_33 AC 1,921 ms
42,632 KB
testcase_34 AC 1,909 ms
42,468 KB
testcase_35 AC 1,951 ms
41,684 KB
testcase_36 AC 1,909 ms
42,764 KB
testcase_37 AC 1,943 ms
42,552 KB
testcase_38 AC 1,934 ms
43,668 KB
testcase_39 AC 1,814 ms
41,684 KB
testcase_40 AC 1,654 ms
42,380 KB
testcase_41 AC 2 ms
6,948 KB
testcase_42 AC 2 ms
6,944 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];
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 <= 20; 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 = 20; 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;
	}

	long long cl = 0, cr = (1LL << 50), cm, maxn = 0;
	for (int i = 0; i < 53; i++) {
		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