結果

問題 No.1211 円環はお断り
ユーザー otera
提出日時 2020-12-03 20:28:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,961 bytes
コンパイル時間 2,436 ms
コンパイル使用メモリ 198,464 KB
最終ジャッジ日時 2025-01-16 14:40:20
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other WA * 25 TLE * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *    author:  otera    
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
    int n, k; cin >> n >> k;
    vector<ll> a(3 * n);
    vector<ll> sum(3 * n + 1, 0);
    rep(i, n) {
        cin >> a[i];
        a[i + 2 * n] = a[i + n] = a[i];
    }
    rep(i, 3 * n) {
        sum[i + 1] = sum[i] + a[i];
    }
    auto check = [&](ll x) {
        if(x >= sum[n]) return true;
        vector<vector<int>> nxt(30, vector<int>(2 * n, 3 * n));
        int j = 0;
        rep(i, 2 * n) {
            while(sum[j] - sum[i] < x) ++ j;
            nxt[0][i] = j;
        }
        rep(j, 29) {
            rep(i, n) {
                nxt[j + 1][i] = (nxt[j][i] >= 2 * n ? 3 * n: nxt[j][nxt[j][i]]);
            }
        }
        rep(i, n) {
            int s = i;
            rep(j, 30) {
                if(k & (1<<j)) {
                    if(s >= 2 * n) return true;
                    s = nxt[j][s];
                }
            }
            cerr << x << " " << i << " " << s << "\n";
            if(s >= i + n) return true;
        }
        return false;
    };
    ll ok = INF, ng = 0;
    while(ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        if(check(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(20);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}
0