結果

問題 No.1211 円環はお断り
ユーザー risujirohrisujiroh
提出日時 2020-08-30 14:12:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,263 bytes
コンパイル時間 4,571 ms
コンパイル使用メモリ 265,048 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-04-27 07:24:32
合計ジャッジ時間 37,870 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 987 ms
11,408 KB
testcase_14 AC 1,104 ms
14,080 KB
testcase_15 AC 1,236 ms
13,696 KB
testcase_16 TLE -
testcase_17 AC 135 ms
6,944 KB
testcase_18 AC 1,123 ms
12,428 KB
testcase_19 AC 157 ms
6,944 KB
testcase_20 AC 177 ms
6,944 KB
testcase_21 AC 177 ms
6,940 KB
testcase_22 AC 1,006 ms
11,776 KB
testcase_23 AC 1,109 ms
13,184 KB
testcase_24 AC 612 ms
8,832 KB
testcase_25 AC 31 ms
6,940 KB
testcase_26 AC 1,271 ms
14,592 KB
testcase_27 AC 650 ms
8,832 KB
testcase_28 AC 1,420 ms
14,848 KB
testcase_29 AC 1,077 ms
12,548 KB
testcase_30 AC 1,369 ms
15,488 KB
testcase_31 AC 588 ms
8,320 KB
testcase_32 AC 1,755 ms
17,280 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 AC 1,879 ms
18,816 KB
testcase_37 AC 1,940 ms
18,944 KB
testcase_38 AC 1,844 ms
18,816 KB
testcase_39 AC 1,871 ms
18,816 KB
testcase_40 AC 1,575 ms
18,944 KB
testcase_41 AC 2 ms
6,944 KB
testcase_42 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.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] = lower_bound(begin(pref), end(pref), pref[i] + m) - begin(pref);
    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