結果

問題 No.1211 円環はお断り
ユーザー milanis48663220milanis48663220
提出日時 2020-08-31 00:44:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,417 bytes
コンパイル時間 652 ms
コンパイル使用メモリ 83,660 KB
実行使用メモリ 13,452 KB
最終ジャッジ日時 2024-04-27 13:47:31
合計ジャッジ時間 9,020 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 86 ms
6,940 KB
testcase_18 RE -
testcase_19 AC 111 ms
6,940 KB
testcase_20 AC 111 ms
6,944 KB
testcase_21 AC 108 ms
6,940 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 22 ms
6,940 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 AC 2 ms
6,944 KB
testcase_42 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

const ll INF = 1e18;

int N, K;
ll A[100005];
ll sum[200005];

int next_offset[100005][20];

void build(ll m){
    for(int i = 0; i < N; i++){
        auto p = lower_bound(sum, sum+2*N+2, sum[i]+m);
        next_offset[i][0] = (p-(sum+i));
    }
    for(int j = 1; j < 18; j++){
        for(int i = 0; i < N; i++){
            next_offset[i][j] = next_offset[i][j-1]+next_offset[(i+next_offset[i][j-1])%N][j-1];
        }
    }
}

ll cnt(int s){
    ll ans = 0;
    for(int i = 0; i < 18; i++){
        if(K&(1<<i)){
            ans += next_offset[s][i];
            s += next_offset[s][i];
            s %= N;
        }
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        sum[i+1] = sum[i]+A[i];
    }
    for(int i = N; i < 2*N; i++){
        sum[i+1] = sum[i]+A[i%N];
    }
    sum[2*N+1] = INF;
    ll l = 1, r = INF/2;
    while(r-l > 1){
        ll c = (l+r)/2;
        build(c);
        bool ok = false;
        for(int i = 0; i < N; i++){
            ll tmp = cnt(i);
            if(tmp <= N) ok = true;
        }
        if(ok) l = c;
        else r = c;
    }
    cout << l << endl;
}
0