結果

問題 No.1211 円環はお断り
ユーザー ForestedForested
提出日時 2020-08-30 15:02:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 983 ms / 2,000 ms
コード長 2,216 bytes
コンパイル時間 3,165 ms
コンパイル使用メモリ 220,408 KB
実行使用メモリ 27,028 KB
最終ジャッジ日時 2023-08-15 09:59:07
合計ジャッジ時間 20,526 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,496 KB
testcase_01 AC 3 ms
7,444 KB
testcase_02 AC 2 ms
7,476 KB
testcase_03 AC 3 ms
7,472 KB
testcase_04 AC 2 ms
7,540 KB
testcase_05 AC 2 ms
7,744 KB
testcase_06 AC 2 ms
7,512 KB
testcase_07 AC 2 ms
7,464 KB
testcase_08 AC 2 ms
7,520 KB
testcase_09 AC 2 ms
7,512 KB
testcase_10 AC 2 ms
7,488 KB
testcase_11 AC 2 ms
7,464 KB
testcase_12 AC 3 ms
7,532 KB
testcase_13 AC 431 ms
20,304 KB
testcase_14 AC 571 ms
22,312 KB
testcase_15 AC 576 ms
22,340 KB
testcase_16 AC 965 ms
26,780 KB
testcase_17 AC 63 ms
9,360 KB
testcase_18 AC 513 ms
20,232 KB
testcase_19 AC 68 ms
9,400 KB
testcase_20 AC 89 ms
11,692 KB
testcase_21 AC 83 ms
11,708 KB
testcase_22 AC 449 ms
20,168 KB
testcase_23 AC 501 ms
22,472 KB
testcase_24 AC 295 ms
16,176 KB
testcase_25 AC 11 ms
7,928 KB
testcase_26 AC 663 ms
24,520 KB
testcase_27 AC 294 ms
15,928 KB
testcase_28 AC 696 ms
24,452 KB
testcase_29 AC 501 ms
20,196 KB
testcase_30 AC 709 ms
24,452 KB
testcase_31 AC 259 ms
15,916 KB
testcase_32 AC 852 ms
26,612 KB
testcase_33 AC 983 ms
27,028 KB
testcase_34 AC 919 ms
26,788 KB
testcase_35 AC 909 ms
26,792 KB
testcase_36 AC 919 ms
26,784 KB
testcase_37 AC 933 ms
26,836 KB
testcase_38 AC 949 ms
26,996 KB
testcase_39 AC 953 ms
26,832 KB
testcase_40 AC 351 ms
26,900 KB
testcase_41 AC 3 ms
7,580 KB
testcase_42 AC 3 ms
7,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

ll a[100000], b[200000];
int nxt[300001], vec[300001][17];

int main() {
    int n, k;
    cin >> n >> k;
    rep(i, n) cin >> a[i];
    
    rep(i, n) b[i] = b[i + n] = a[i];
    
    ll s = 0;
    rep(i, n) s += a[i];
    
    rep(i, 300001) nxt[i] = 3 * n;
    
    auto judge = [&](ll x) -> bool {
        if (s < x) return false;
        {
            int now = 0; ll sum = 0;
            while (sum < x) {
                sum += b[now]; ++now;
            }
            nxt[0] = now;
            rep(i, 1, n) {
                sum -= b[i - 1];
                while (sum < x) {
                    sum += b[now]; ++now;
                }
                nxt[i] = now;
            }
        }
        rep(i, n) nxt[i + n] = nxt[i] + n;
        rep(i, 3 * n + 1) vec[i][0] = nxt[i];
        rep(j, 1, 17) rep(i, 3 * n + 1) vec[i][j] = vec[vec[i][j - 1]][j - 1];
        bool ans = false;
        rep(i, n) {
            int now = i;
            rep(j, 17) {
                if ((k >> j) & 1) now = vec[now][j];
            }
            if (now <= i + n) ans = true;
        }
        return ans;
    };
    
    //judge(4);
    
    ll ok = inf, ng = 1e15;
    rep(i, n) chmin(ok, a[i]);
    while (ng - ok > 1) {
        ll mid = (ng + ok) / 2;
        (judge(mid) ? ok : ng) = mid;
    }
    
    cout << ok << "\n";
    return 0;
}
0