結果

問題 No.1211 円環はお断り
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-09-01 03:59:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,614 bytes
コンパイル時間 1,703 ms
コンパイル使用メモリ 172,112 KB
実行使用メモリ 32,896 KB
最終ジャッジ日時 2024-04-28 14:20:08
合計ジャッジ時間 32,106 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1,187 ms
15,856 KB
testcase_14 AC 1,705 ms
19,968 KB
testcase_15 AC 1,673 ms
19,488 KB
testcase_16 TLE -
testcase_17 AC 155 ms
5,376 KB
testcase_18 AC 1,361 ms
17,700 KB
testcase_19 AC 164 ms
5,424 KB
testcase_20 AC 220 ms
6,188 KB
testcase_21 AC 210 ms
6,016 KB
testcase_22 AC 1,283 ms
16,372 KB
testcase_23 AC 1,519 ms
18,540 KB
testcase_24 AC 766 ms
11,964 KB
testcase_25 AC 27 ms
5,376 KB
testcase_26 AC 1,830 ms
21,000 KB
testcase_27 AC 788 ms
12,032 KB
testcase_28 AC 1,971 ms
21,376 KB
testcase_29 AC 1,463 ms
17,536 KB
testcase_30 TLE -
testcase_31 AC 702 ms
10,952 KB
testcase_32 TLE -
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.09.01 03:58:33
**/

#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(2 * n + 1,vector<int>(20));
    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[i][0] = t;
        next[i + n][0] = min(2 * n,t + n);
        sum -= a[i];
    }
    for (int i = 0; i < 20; i++) {
        next[2 * n][i] = 2 * n;
    } 
    for (int i = 0; i < 19; i++) {
        for (int j = 0; j < n; j++) {
            next[j][i + 1] = next[next[j][i]][i];
            next[j + n][i + 1] = next[next[j + n][i]][i];
        }
    }
    for (int i = 0; i < n; i++) {
        int p = k;
        int q = 0;
        int now = i;
        while(p) {
            if (p & 1) {
                now = next[now][q];
            }
            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