結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 633 ms
11,972 KB
testcase_14 AC 767 ms
14,920 KB
testcase_15 AC 800 ms
14,604 KB
testcase_16 AC 1,277 ms
19,928 KB
testcase_17 AC 101 ms
4,572 KB
testcase_18 AC 818 ms
13,400 KB
testcase_19 AC 113 ms
4,612 KB
testcase_20 AC 134 ms
5,140 KB
testcase_21 AC 126 ms
4,888 KB
testcase_22 AC 643 ms
12,280 KB
testcase_23 AC 717 ms
14,064 KB
testcase_24 AC 404 ms
9,344 KB
testcase_25 AC 25 ms
4,380 KB
testcase_26 AC 872 ms
15,656 KB
testcase_27 AC 423 ms
9,376 KB
testcase_28 AC 949 ms
15,920 KB
testcase_29 AC 713 ms
13,404 KB
testcase_30 AC 900 ms
16,452 KB
testcase_31 AC 409 ms
8,532 KB
testcase_32 AC 1,125 ms
18,560 KB
testcase_33 AC 1,265 ms
20,208 KB
testcase_34 AC 1,264 ms
20,208 KB
testcase_35 AC 1,242 ms
20,152 KB
testcase_36 AC 1,196 ms
20,200 KB
testcase_37 AC 1,194 ms
20,144 KB
testcase_38 AC 1,192 ms
20,172 KB
testcase_39 AC 1,189 ms
20,144 KB
testcase_40 AC 1,054 ms
20,300 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,380 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;

    auto to = vec(20, vec(n, 0LL));

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

        {
            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