結果

問題 No.1211 円環はお断り
ユーザー chocopuu
提出日時 2020-08-30 20:39:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,799 bytes
コンパイル時間 2,527 ms
コンパイル使用メモリ 201,068 KB
最終ジャッジ日時 2025-01-14 02:05:25
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32 TLE * 9
権限があれば一括ダウンロードができます

ソースコード

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;
}

signed main(){
	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, 30) {
				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 = 1e18 + 1;
	while(r - l > 1){
		int c = (l + r) / 2;
		if(f(c)) l = c;
		else r = c;
	}
	cout << l << endl;
}
0