結果

問題 No.1211 円環はお断り
ユーザー vwxyzvwxyz
提出日時 2023-03-31 04:17:21
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,407 ms / 2,000 ms
コード長 1,654 bytes
コンパイル時間 3,385 ms
コンパイル使用メモリ 253,292 KB
実行使用メモリ 26,060 KB
最終ジャッジ日時 2023-10-23 17:55:01
合計ジャッジ時間 27,574 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 579 ms
15,200 KB
testcase_14 AC 721 ms
14,784 KB
testcase_15 AC 833 ms
18,700 KB
testcase_16 AC 1,371 ms
25,796 KB
testcase_17 AC 80 ms
5,236 KB
testcase_18 AC 781 ms
16,956 KB
testcase_19 AC 80 ms
5,236 KB
testcase_20 AC 119 ms
5,780 KB
testcase_21 AC 106 ms
5,512 KB
testcase_22 AC 615 ms
15,732 KB
testcase_23 AC 759 ms
17,848 KB
testcase_24 AC 401 ms
11,632 KB
testcase_25 AC 16 ms
4,348 KB
testcase_26 AC 937 ms
20,020 KB
testcase_27 AC 414 ms
11,636 KB
testcase_28 AC 991 ms
20,464 KB
testcase_29 AC 674 ms
16,876 KB
testcase_30 AC 1,015 ms
21,144 KB
testcase_31 AC 351 ms
10,744 KB
testcase_32 AC 1,192 ms
23,936 KB
testcase_33 AC 1,353 ms
26,060 KB
testcase_34 AC 1,332 ms
26,060 KB
testcase_35 AC 1,309 ms
26,060 KB
testcase_36 AC 1,325 ms
26,060 KB
testcase_37 AC 1,283 ms
26,024 KB
testcase_38 AC 1,407 ms
26,060 KB
testcase_39 AC 1,365 ms
26,060 KB
testcase_40 AC 790 ms
16,724 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<long long> A(2*N+1);
    long long sum_A = 0;
    for (int i = 1; i < N+1; i++) {
        cin >> A[i];
        A[i+N]=A[i];
        sum_A += A[i];
    }
    for (int i = 1; i < 2*N+1; i++) {
        A[i] += A[i-1];
    }
    long long ok = 0, ng = sum_A / K+1;
    while (abs(ok-ng) > 1) {
        long long mid = (ok+ng) / 2;
        vector<int> perm(2*N+1);
        for (int i = 0; i < 2*N+1; i++) {
            perm[i] = i;
        }
        int r = 0;
        for (int l = 0; l < 2*N; l++) {
            while (r < 2*N && A[r]-A[l] < mid) {
                r++;
            }
            perm[l] = r;
        }
        int k = log2(K) + 1;
        vector<vector<int>> perm_doub(2*N+1, vector<int>(k));
        for (int n = 0; n < 2*N+1; n++) {
            perm_doub[n][0] = perm[n];
        }
        for (int kk = 1; kk < k; kk++) {
            for (int n = 0; n < 2*N+1; n++) {
                perm_doub[n][kk] = perm_doub[perm_doub[n][kk-1]][kk-1];
            }
        }
        bool found = false;
        for (int i = 0; i < N; i++) {
            int x = i;
            for (int kk = 0; kk < k; kk++) {
                if (K>>kk & 1) {
                    x = perm_doub[x][kk];
                }
            }
            if (mid < A[i]) {
                break;
            }
            if (i + 1 <= x && x <= i + N) {
                found = true;
                break;
            }
        }
        if(found){
            ok=mid;
        }
        else{
            ng = mid;
        }
    }
    cout << ok << endl;
    return 0;
}
0