結果

問題 No.1211 円環はお断り
ユーザー msm1993msm1993
提出日時 2020-10-08 10:19:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 716 ms / 2,000 ms
コード長 1,615 bytes
コンパイル時間 1,475 ms
コンパイル使用メモリ 170,052 KB
実行使用メモリ 20,372 KB
最終ジャッジ日時 2023-09-27 11:45:36
合計ジャッジ時間 16,339 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 329 ms
12,060 KB
testcase_14 AC 439 ms
14,880 KB
testcase_15 AC 439 ms
14,688 KB
testcase_16 AC 672 ms
19,972 KB
testcase_17 AC 48 ms
4,604 KB
testcase_18 AC 385 ms
13,320 KB
testcase_19 AC 49 ms
4,684 KB
testcase_20 AC 67 ms
5,276 KB
testcase_21 AC 64 ms
5,088 KB
testcase_22 AC 344 ms
12,360 KB
testcase_23 AC 407 ms
14,196 KB
testcase_24 AC 219 ms
9,408 KB
testcase_25 AC 11 ms
4,376 KB
testcase_26 AC 479 ms
15,688 KB
testcase_27 AC 219 ms
9,348 KB
testcase_28 AC 504 ms
15,952 KB
testcase_29 AC 374 ms
13,276 KB
testcase_30 AC 494 ms
16,464 KB
testcase_31 AC 192 ms
8,560 KB
testcase_32 AC 606 ms
18,584 KB
testcase_33 AC 685 ms
20,340 KB
testcase_34 AC 695 ms
20,276 KB
testcase_35 AC 695 ms
20,224 KB
testcase_36 AC 706 ms
20,264 KB
testcase_37 AC 716 ms
20,292 KB
testcase_38 AC 670 ms
20,372 KB
testcase_39 AC 671 ms
20,248 KB
testcase_40 AC 38 ms
4,376 KB
testcase_41 AC 2 ms
4,384 KB
testcase_42 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 解法見て書いただけ 要復習

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.09.01 04:06:21
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int n,k;
vector<int> a;

bool f(ll x) {
    vector<vector<int>> next(20,vector<int>(2 * n + 1));
    ll sum = 0;
    int t = 0;
    for (int i = 0; i < n; i++) {
        while(t < 2 * n && sum < x) {
            sum += a[t % n];
            t++;
            if (i + n <= t) return false;
        }
        next[0][i] = t;
        next[0][i + n] = min(2 * n,t + n);
        sum -= a[i];
    }
    for (int i = 0; i < 20; i++) {
        next[i][2 * n] = 2 * n;
    } 
    for (int i = 0; i < 19; i++) {
        for (int j = 0; j < n; j++) {
            next[i + 1][j] = next[i][next[i][j]];
            next[i + 1][j + n] = next[i][next[i][j + n]];
        }
    }
    for (int i = 0; i < n; i++) {
        int p = k;
        int q = 0;
        int now = i;
        while(p) {
            if (p & 1) {
                now = next[q][now];
            }
            p >>= 1;
            q++;
        }
        if (now <= n + i) return true;
    }
    return false;
}

int main() {
    cin >> n >> k;
    a.resize(2 * n);
    ll l = 0, r = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i + n] = a[i];
        r += a[i];
    }
    if (k == 1) {
        cout << r - 1 << endl;
        return 0;
    }
    while(r - l > 1) {
        ll mid = l + (r - l) / 2;
        if (f(mid)) {
            l = mid;
        }
        else {
            r = mid;
        }
    }
    cout << l << endl;
    return 0;
}
0