結果

問題 No.1211 円環はお断り
ユーザー ForestedForested
提出日時 2020-08-30 14:58:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,232 bytes
コンパイル時間 5,107 ms
コンパイル使用メモリ 225,080 KB
実行使用メモリ 41,072 KB
最終ジャッジ日時 2023-08-09 12:52:01
合計ジャッジ時間 12,634 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 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,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 675 ms
20,760 KB
testcase_14 AC 1,031 ms
26,736 KB
testcase_15 AC 1,032 ms
25,852 KB
testcase_16 TLE -
testcase_17 AC 98 ms
6,040 KB
testcase_18 AC 928 ms
23,392 KB
testcase_19 AC 102 ms
6,296 KB
testcase_20 AC 131 ms
7,088 KB
testcase_21 AC 124 ms
7,276 KB
testcase_22 AC 782 ms
21,488 KB
testcase_23 AC 969 ms
24,804 KB
testcase_24 AC 451 ms
15,164 KB
testcase_25 AC 14 ms
4,384 KB
testcase_26 AC 1,421 ms
27,976 KB
testcase_27 AC 439 ms
15,620 KB
testcase_28 AC 1,344 ms
28,596 KB
testcase_29 AC 816 ms
23,504 KB
testcase_30 AC 1,370 ms
29,548 KB
testcase_31 AC 400 ms
13,836 KB
testcase_32 AC 1,714 ms
33,880 KB
testcase_33 TLE -
testcase_34 AC 1,949 ms
36,868 KB
testcase_35 AC 1,920 ms
37,108 KB
testcase_36 AC 1,963 ms
37,060 KB
testcase_37 AC 1,911 ms
37,128 KB
testcase_38 AC 1,864 ms
37,112 KB
testcase_39 AC 1,968 ms
37,136 KB
testcase_40 AC 1,067 ms
37,132 KB
testcase_41 AC 2 ms
4,384 KB
testcase_42 AC 1 ms
4,380 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;

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    
    vector<ll> b(2 * n);
    rep(i, n) b[i] = b[i + n] = a[i];
    
    ll s = 0;
    rep(i, n) s += a[i];
    
    vector<int> nxt(3 * n + 1, 3 * n);
    vector<vector<int>> vec(3 * n + 1, vector<int>(17));
    
    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 = -1, ng = 1e15;
    while (ng - ok > 1) {
        ll mid = (ng + ok) / 2;
        (judge(mid) ? ok : ng) = mid;
    }
    
    cout << ok << "\n";
    return 0;
}
0