結果

問題 No.1211 円環はお断り
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-09-01 04:16:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 887 ms / 2,000 ms
コード長 1,615 bytes
コンパイル時間 1,611 ms
コンパイル使用メモリ 169,936 KB
実行使用メモリ 20,352 KB
最終ジャッジ日時 2023-08-15 10:21:41
合計ジャッジ時間 17,211 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 398 ms
11,980 KB
testcase_14 AC 546 ms
14,968 KB
testcase_15 AC 542 ms
14,624 KB
testcase_16 AC 832 ms
19,996 KB
testcase_17 AC 55 ms
4,576 KB
testcase_18 AC 465 ms
13,472 KB
testcase_19 AC 55 ms
4,632 KB
testcase_20 AC 76 ms
4,996 KB
testcase_21 AC 72 ms
5,008 KB
testcase_22 AC 414 ms
12,380 KB
testcase_23 AC 497 ms
13,948 KB
testcase_24 AC 253 ms
9,328 KB
testcase_25 AC 13 ms
4,376 KB
testcase_26 AC 599 ms
15,712 KB
testcase_27 AC 259 ms
9,436 KB
testcase_28 AC 618 ms
15,976 KB
testcase_29 AC 474 ms
13,392 KB
testcase_30 AC 636 ms
16,512 KB
testcase_31 AC 222 ms
8,804 KB
testcase_32 AC 764 ms
18,668 KB
testcase_33 AC 875 ms
20,268 KB
testcase_34 AC 860 ms
20,304 KB
testcase_35 AC 843 ms
20,304 KB
testcase_36 AC 868 ms
20,316 KB
testcase_37 AC 887 ms
20,256 KB
testcase_38 AC 854 ms
20,352 KB
testcase_39 AC 854 ms
20,296 KB
testcase_40 AC 42 ms
4,380 KB
testcase_41 AC 1 ms
4,380 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