結果

問題 No.1211 円環はお断り
ユーザー milanis48663220milanis48663220
提出日時 2020-08-31 00:57:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,637 bytes
コンパイル時間 1,046 ms
コンパイル使用メモリ 86,028 KB
実行使用メモリ 25,444 KB
最終ジャッジ日時 2023-08-15 10:12:01
合計ジャッジ時間 9,240 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
11,440 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1,098 ms
14,836 KB
testcase_14 AC 1,479 ms
17,388 KB
testcase_15 AC 1,429 ms
17,212 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

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

ll next_offset[100005][20];
bool used[100005];

void clear_used(){
    for(int i = 0; i < N; i++) used[i] = false;
}

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

vector<int> bt;

ll cnt(int s){
    ll ans = 0;
    for(int i : bt){
        used[s] = true;
        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 < 18; i++){
        if(K&(1<<i)) bt.push_back(i);
    }
    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;
        clear_used();
        build(c);
        bool ok = false;
        for(int i = 0; i < N; i++){
            if(!used[i]){
                ll tmp = cnt(i);
                if(tmp <= N) ok = true;
            }
        }
        if(ok) l = c;
        else r = c;
    }
    cout << l << endl;
}
0