結果

問題 No.1211 円環はお断り
ユーザー MisterMister
提出日時 2020-08-30 17:16:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,848 ms / 2,000 ms
コード長 1,537 bytes
コンパイル時間 982 ms
コンパイル使用メモリ 77,952 KB
実行使用メモリ 20,480 KB
最終ジャッジ日時 2024-05-02 21:37:06
合計ジャッジ時間 33,850 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 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 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 900 ms
12,160 KB
testcase_14 AC 1,126 ms
15,044 KB
testcase_15 AC 1,153 ms
14,848 KB
testcase_16 AC 1,806 ms
20,096 KB
testcase_17 AC 131 ms
5,376 KB
testcase_18 AC 1,118 ms
13,568 KB
testcase_19 AC 148 ms
5,376 KB
testcase_20 AC 176 ms
5,376 KB
testcase_21 AC 168 ms
5,376 KB
testcase_22 AC 910 ms
12,428 KB
testcase_23 AC 1,038 ms
14,080 KB
testcase_24 AC 565 ms
9,348 KB
testcase_25 AC 31 ms
5,376 KB
testcase_26 AC 1,265 ms
15,744 KB
testcase_27 AC 594 ms
9,472 KB
testcase_28 AC 1,360 ms
16,128 KB
testcase_29 AC 1,031 ms
13,312 KB
testcase_30 AC 1,309 ms
16,512 KB
testcase_31 AC 560 ms
8,704 KB
testcase_32 AC 1,598 ms
18,944 KB
testcase_33 AC 1,817 ms
20,224 KB
testcase_34 AC 1,848 ms
20,408 KB
testcase_35 AC 1,783 ms
20,224 KB
testcase_36 AC 1,745 ms
20,480 KB
testcase_37 AC 1,743 ms
20,352 KB
testcase_38 AC 1,749 ms
20,352 KB
testcase_39 AC 1,756 ms
20,352 KB
testcase_40 AC 1,619 ms
20,480 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <numeric>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

using lint = long long;

void solve() {
    int n, k;
    std::cin >> n >> k;

    std::vector<lint> xs(n);
    for (auto& x : xs) std::cin >> x;

    lint ok = 0, ng = std::accumulate(xs.begin(), xs.end(), 0LL) + 1;
    while (ng - ok > 1) {
        lint mid = (ok + ng) / 2;

        auto to = vec(20, vec(n, 0LL));
        {
            int r = 0;
            lint sum = 0;
            for (int l = 0; l < n; ++l) {
                while (sum < mid) {
                    sum += xs[r % n];
                    ++r;
                }
                to[0][l] = r - l;
                sum -= xs[l];
            }
        }

        for (int d = 0; d + 1 < 20; ++d) {
            for (int i = 0; i < n; ++i) {
                to[d + 1][i] = to[d][i] + to[d][(i + to[d][i]) % n];
            }
        }

        bool judge = false;
        for (int s = 0; s < n; ++s) {
            int v = s;
            lint sum = 0;

            for (int d = 0; d < 20; ++d) {
                if ((~k >> d) & 1) continue;
                sum += to[d][v];
                (v += to[d][v]) %= n;
            }

            if (sum <= n) judge = true;
        }

        if (judge) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    std::cout << ok << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0