結果

問題 No.1211 円環はお断り
ユーザー MisterMister
提出日時 2020-08-30 17:16:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,826 ms / 2,000 ms
コード長 1,537 bytes
コンパイル時間 1,050 ms
コンパイル使用メモリ 78,152 KB
実行使用メモリ 20,364 KB
最終ジャッジ日時 2023-08-15 10:05:54
合計ジャッジ時間 33,987 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 893 ms
12,116 KB
testcase_14 AC 1,119 ms
14,932 KB
testcase_15 AC 1,140 ms
14,628 KB
testcase_16 AC 1,789 ms
20,128 KB
testcase_17 AC 131 ms
4,684 KB
testcase_18 AC 1,117 ms
13,408 KB
testcase_19 AC 145 ms
4,584 KB
testcase_20 AC 176 ms
5,096 KB
testcase_21 AC 170 ms
5,104 KB
testcase_22 AC 905 ms
12,392 KB
testcase_23 AC 1,027 ms
14,036 KB
testcase_24 AC 570 ms
9,444 KB
testcase_25 AC 30 ms
4,384 KB
testcase_26 AC 1,241 ms
15,668 KB
testcase_27 AC 600 ms
9,372 KB
testcase_28 AC 1,350 ms
15,924 KB
testcase_29 AC 1,022 ms
13,312 KB
testcase_30 AC 1,312 ms
16,448 KB
testcase_31 AC 556 ms
8,532 KB
testcase_32 AC 1,605 ms
18,800 KB
testcase_33 AC 1,814 ms
20,364 KB
testcase_34 AC 1,826 ms
20,276 KB
testcase_35 AC 1,784 ms
20,264 KB
testcase_36 AC 1,738 ms
20,364 KB
testcase_37 AC 1,731 ms
20,360 KB
testcase_38 AC 1,745 ms
20,288 KB
testcase_39 AC 1,752 ms
20,364 KB
testcase_40 AC 1,618 ms
20,276 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,384 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