結果

問題 No.1211 円環はお断り
ユーザー chocopuuchocopuu
提出日時 2020-08-30 20:47:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,786 ms / 2,000 ms
コード長 1,880 bytes
コンパイル時間 2,236 ms
コンパイル使用メモリ 207,460 KB
実行使用メモリ 35,556 KB
最終ジャッジ日時 2023-08-15 10:09:40
合計ジャッジ時間 33,004 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 807 ms
18,736 KB
testcase_14 AC 792 ms
16,304 KB
testcase_15 AC 1,056 ms
22,232 KB
testcase_16 AC 1,725 ms
34,036 KB
testcase_17 AC 96 ms
5,424 KB
testcase_18 AC 926 ms
20,140 KB
testcase_19 AC 105 ms
5,784 KB
testcase_20 AC 125 ms
5,948 KB
testcase_21 AC 138 ms
6,268 KB
testcase_22 AC 841 ms
19,236 KB
testcase_23 AC 1,013 ms
21,988 KB
testcase_24 AC 539 ms
13,956 KB
testcase_25 AC 23 ms
4,380 KB
testcase_26 AC 1,183 ms
24,816 KB
testcase_27 AC 557 ms
13,944 KB
testcase_28 AC 1,240 ms
26,432 KB
testcase_29 AC 939 ms
20,916 KB
testcase_30 AC 1,321 ms
27,544 KB
testcase_31 AC 448 ms
12,336 KB
testcase_32 AC 1,562 ms
31,716 KB
testcase_33 AC 1,739 ms
34,684 KB
testcase_34 AC 1,734 ms
35,556 KB
testcase_35 AC 1,750 ms
34,484 KB
testcase_36 AC 1,773 ms
35,244 KB
testcase_37 AC 1,786 ms
34,848 KB
testcase_38 AC 1,714 ms
34,584 KB
testcase_39 AC 1,723 ms
34,540 KB
testcase_40 AC 433 ms
9,344 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

vector<vector<int>>getDoubling(vector<int>&a, int K) {
	vector<vector<int>>dp(log2(K) + 1, vector<int>(a.size(), -1));
	REP(i, a.size()) dp[0][i] = a[i];
	REP(i, log2(K)) {
		REP(j, a.size()) {
			if(dp[i][j] == a.size()) dp[i + 1][j] = dp[i][j];
			else dp[i + 1][j] = dp[i][dp[i][j]];
		}
	}
	return dp;
}

#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)

signed main(){
	IOS();
	int N, K;
	cin >> N >> K;
	vector<int>a(N);
	cin >> a;
	REP(i, N) a.emplace_back(a[i]);
	a.insert(a.begin(), 0);
	REP(i, a.size() - 1) a[i + 1] += a[i];

	auto f =[&](int x) -> bool {
		vector<int>to(a.size());
		REP(i, a.size()) {
			to[i] = lower_bound(ALL(a), a[i] + x) - a.begin();
		}
		auto dp = getDoubling(to, K);

		REP(i, N) {
			int now = i;
			REP(j, 18) {
				if(K & (1ll << j)) {
					now = dp[j][now];
					if(now == a.size()) return false;
				}
			}
			//out(i, now);
			if(now <= i + N) return true;
		}
		return false;
	};
	
	int l = -1, r = 1e14 + 1;
	while(r - l > 1){
		int c = (l + r) / 2;
		if(f(c)) l = c;
		else r = c;
	}
	cout << l << endl;
}
0