結果

問題 No.1211 円環はお断り
ユーザー e869120e869120
提出日時 2021-02-26 09:20:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,889 ms / 2,000 ms
コード長 1,153 bytes
コンパイル時間 4,845 ms
コンパイル使用メモリ 68,256 KB
実行使用メモリ 43,484 KB
最終ジャッジ日時 2024-04-09 22:35:54
合計ジャッジ時間 34,521 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 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,940 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 632 ms
24,496 KB
testcase_14 AC 500 ms
31,252 KB
testcase_15 AC 858 ms
30,028 KB
testcase_16 AC 1,874 ms
42,008 KB
testcase_17 AC 65 ms
8,852 KB
testcase_18 AC 662 ms
27,844 KB
testcase_19 AC 74 ms
10,240 KB
testcase_20 AC 88 ms
10,836 KB
testcase_21 AC 95 ms
10,024 KB
testcase_22 AC 612 ms
25,308 KB
testcase_23 AC 733 ms
28,468 KB
testcase_24 AC 373 ms
19,056 KB
testcase_25 AC 10 ms
6,944 KB
testcase_26 AC 901 ms
32,376 KB
testcase_27 AC 386 ms
19,268 KB
testcase_28 AC 991 ms
33,068 KB
testcase_29 AC 713 ms
27,744 KB
testcase_30 AC 1,166 ms
33,848 KB
testcase_31 AC 332 ms
17,284 KB
testcase_32 AC 1,593 ms
39,924 KB
testcase_33 AC 1,877 ms
43,264 KB
testcase_34 AC 1,884 ms
43,480 KB
testcase_35 AC 1,889 ms
43,484 KB
testcase_36 AC 1,723 ms
43,324 KB
testcase_37 AC 1,815 ms
42,444 KB
testcase_38 AC 1,672 ms
42,168 KB
testcase_39 AC 1,734 ms
41,984 KB
testcase_40 AC 161 ms
41,884 KB
testcase_41 AC 2 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 = (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