結果

問題 No.1211 円環はお断り
ユーザー risujirohrisujiroh
提出日時 2020-08-30 14:16:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,648 ms / 2,000 ms
コード長 1,415 bytes
コンパイル時間 5,954 ms
コンパイル使用メモリ 374,880 KB
実行使用メモリ 18,812 KB
最終ジャッジ日時 2023-08-15 09:55:55
合計ジャッジ時間 32,978 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 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,384 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 754 ms
11,276 KB
testcase_14 AC 862 ms
13,900 KB
testcase_15 AC 926 ms
13,628 KB
testcase_16 AC 1,557 ms
18,388 KB
testcase_17 AC 113 ms
4,428 KB
testcase_18 AC 876 ms
12,384 KB
testcase_19 AC 124 ms
4,520 KB
testcase_20 AC 144 ms
4,852 KB
testcase_21 AC 143 ms
4,844 KB
testcase_22 AC 778 ms
11,492 KB
testcase_23 AC 829 ms
13,024 KB
testcase_24 AC 467 ms
8,800 KB
testcase_25 AC 26 ms
4,380 KB
testcase_26 AC 990 ms
14,568 KB
testcase_27 AC 507 ms
8,804 KB
testcase_28 AC 1,159 ms
15,028 KB
testcase_29 AC 837 ms
12,444 KB
testcase_30 AC 1,092 ms
15,160 KB
testcase_31 AC 459 ms
8,048 KB
testcase_32 AC 1,387 ms
17,316 KB
testcase_33 AC 1,648 ms
18,756 KB
testcase_34 AC 1,547 ms
18,764 KB
testcase_35 AC 1,576 ms
18,688 KB
testcase_36 AC 1,408 ms
18,792 KB
testcase_37 AC 1,500 ms
18,764 KB
testcase_38 AC 1,388 ms
18,768 KB
testcase_39 AC 1,432 ms
18,768 KB
testcase_40 AC 1,134 ms
18,812 KB
testcase_41 AC 1 ms
4,384 KB
testcase_42 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,bmi,bmi2,lzcnt")
#endif

#include <bits/extc++.h>
#include <x86intrin.h>

#ifndef DUMP
#define DUMP(...) void(0)
#endif

using namespace std;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int64_t> pref(2 * n + 1);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    pref[i + 1] = pref[i] + a;
  }
  for (int i = n + 1; i <= 2 * n; ++i) pref[i] = pref[i - n] + pref[n];
  DUMP(pref);

  constexpr int lg = 17;
  auto check = [&](int64_t m) -> bool {
    vector to(lg, vector<int64_t>(n));
    for (int i = 0; i < n; ++i) {
      to[0][i] = i ? to[0][i - 1] : 0;
      while (pref[to[0][i]] - pref[i] < m) ++to[0][i];
    }
    for (int s = 1; s < lg; ++s)
      for (int i = 0; i < n; ++i) {
        int ni = to[s - 1][i] % n;
        to[s][i] = to[s - 1][i] + (to[s - 1][ni] - ni);
      }
    for (int i = 0; i < n; ++i) {
      int t = k;
      int64_t cur = i;
      for (int s = lg; s--;) {
        if (t < 1 << s) continue;
        t -= 1 << s;
        cur += to[s][cur % n] - cur % n;
      }
      if (cur - i <= n) return true;
    }
    return false;
  };

  int64_t ok = 1, ng = pref.back() + 1;
  while (ng - ok > 1) {
    auto mid = (ok + ng) / 2;
    (check(mid) ? ok : ng) = mid;
  }
  cout << ok << '\n';
}
0