結果

問題 No.1211 円環はお断り
ユーザー leaf_1415leaf_1415
提出日時 2020-08-30 14:14:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,097 ms / 2,000 ms
コード長 1,646 bytes
コンパイル時間 929 ms
コンパイル使用メモリ 75,000 KB
実行使用メモリ 21,616 KB
最終ジャッジ日時 2023-08-15 09:55:16
合計ジャッジ時間 20,188 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,464 KB
testcase_01 AC 2 ms
7,456 KB
testcase_02 AC 2 ms
7,540 KB
testcase_03 AC 2 ms
7,448 KB
testcase_04 AC 2 ms
7,464 KB
testcase_05 AC 2 ms
7,500 KB
testcase_06 AC 2 ms
7,460 KB
testcase_07 AC 2 ms
7,460 KB
testcase_08 AC 2 ms
7,456 KB
testcase_09 AC 2 ms
7,492 KB
testcase_10 AC 2 ms
7,528 KB
testcase_11 AC 2 ms
7,644 KB
testcase_12 AC 2 ms
7,448 KB
testcase_13 AC 539 ms
16,092 KB
testcase_14 AC 670 ms
18,560 KB
testcase_15 AC 729 ms
18,512 KB
testcase_16 AC 1,057 ms
21,312 KB
testcase_17 AC 80 ms
8,612 KB
testcase_18 AC 703 ms
16,280 KB
testcase_19 AC 82 ms
8,640 KB
testcase_20 AC 108 ms
9,012 KB
testcase_21 AC 101 ms
8,980 KB
testcase_22 AC 557 ms
16,156 KB
testcase_23 AC 657 ms
18,480 KB
testcase_24 AC 354 ms
13,672 KB
testcase_25 AC 20 ms
7,776 KB
testcase_26 AC 771 ms
18,916 KB
testcase_27 AC 362 ms
13,860 KB
testcase_28 AC 823 ms
18,772 KB
testcase_29 AC 628 ms
16,292 KB
testcase_30 AC 787 ms
20,804 KB
testcase_31 AC 339 ms
13,632 KB
testcase_32 AC 983 ms
21,372 KB
testcase_33 AC 1,055 ms
21,320 KB
testcase_34 AC 1,097 ms
21,388 KB
testcase_35 AC 1,084 ms
21,476 KB
testcase_36 AC 991 ms
21,496 KB
testcase_37 AC 1,072 ms
21,344 KB
testcase_38 AC 921 ms
21,408 KB
testcase_39 AC 935 ms
21,616 KB
testcase_40 AC 38 ms
21,540 KB
testcase_41 AC 2 ms
7,516 KB
testcase_42 AC 2 ms
7,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n, k;
llint a[300005], sum[300005];
llint succ[100005][17];

bool check(llint d)
{
	if(d > sum[n]) return false;
	
	llint r = -1;
	for(int i = 0; i < n; i++){
		while(r < i || sum[r]-sum[i] < d) r++;
		succ[i][0] = r-i;//lower_bound(sum, sum+3*n, sum[i] + d) - (sum+i);
	}
	for(int i = 1; i < 17; i++){
		for(int j = 0; j < n; j++){
			succ[j][i] = succ[j][i-1] + succ[(j+succ[j][i-1])%n][i-1];
		}
	}
	
	for(int i = 0; i < n; i++){
		llint v = i, s = 0;
		for(int j = 16; j >= 0; j--){
			if(k & (1<<j)){
				s += succ[v][j];
				if(s > n) goto end;
				v += succ[v][j], v %= n;
			}
		}
		return true;
		end:;
	}
	return false;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = n; i < 3*n; i++) a[i] = a[i%n];
	
	llint s = 0;
	for(int i = 0; i < 3*n; i++){
		sum[i] = s;
		s += a[i];
	}
	
	llint ub = 2e14, lb = 0, mid;
	while(ub-lb>1){
		mid = (ub+lb)/2;
		if(check(mid)) lb = mid;
		else ub = mid;
	}
	cout << lb << endl;
	
	return 0;
}
0