結果

問題 No.1211 円環はお断り
ユーザー leaf_1415leaf_1415
提出日時 2020-08-30 14:09:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,655 ms / 2,000 ms
コード長 1,563 bytes
コンパイル時間 962 ms
コンパイル使用メモリ 80,352 KB
実行使用メモリ 21,392 KB
最終ジャッジ日時 2024-04-27 07:22:05
合計ジャッジ時間 28,441 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,520 KB
testcase_01 AC 2 ms
7,392 KB
testcase_02 AC 2 ms
7,520 KB
testcase_03 AC 1 ms
7,520 KB
testcase_04 AC 2 ms
7,520 KB
testcase_05 AC 2 ms
7,516 KB
testcase_06 AC 2 ms
7,396 KB
testcase_07 AC 2 ms
7,652 KB
testcase_08 AC 1 ms
7,388 KB
testcase_09 AC 2 ms
7,396 KB
testcase_10 AC 2 ms
7,528 KB
testcase_11 AC 3 ms
7,652 KB
testcase_12 AC 2 ms
7,516 KB
testcase_13 AC 776 ms
17,004 KB
testcase_14 AC 849 ms
18,496 KB
testcase_15 AC 977 ms
18,576 KB
testcase_16 AC 1,581 ms
21,356 KB
testcase_17 AC 111 ms
10,100 KB
testcase_18 AC 974 ms
16,360 KB
testcase_19 AC 123 ms
8,676 KB
testcase_20 AC 140 ms
10,288 KB
testcase_21 AC 134 ms
8,928 KB
testcase_22 AC 779 ms
16,224 KB
testcase_23 AC 829 ms
16,616 KB
testcase_24 AC 473 ms
13,876 KB
testcase_25 AC 28 ms
7,904 KB
testcase_26 AC 1,086 ms
19,296 KB
testcase_27 AC 514 ms
13,752 KB
testcase_28 AC 1,105 ms
20,812 KB
testcase_29 AC 847 ms
16,344 KB
testcase_30 AC 1,093 ms
20,880 KB
testcase_31 AC 497 ms
13,800 KB
testcase_32 AC 1,429 ms
21,180 KB
testcase_33 AC 1,655 ms
21,392 KB
testcase_34 AC 1,654 ms
21,388 KB
testcase_35 AC 1,613 ms
21,388 KB
testcase_36 AC 1,445 ms
21,392 KB
testcase_37 AC 1,528 ms
21,388 KB
testcase_38 AC 1,459 ms
21,264 KB
testcase_39 AC 1,450 ms
21,392 KB
testcase_40 AC 574 ms
21,388 KB
testcase_41 AC 2 ms
7,520 KB
testcase_42 AC 2 ms
7,392 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;
	
	for(int i = 0; i < n; i++){
		succ[i][0] = 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];
				v += succ[v][j], v %= n;
			}
		}
		if(s <= n) return true;
	}
	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 = 1e15, 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