結果

問題 No.1211 円環はお断り
ユーザー risujirohrisujiroh
提出日時 2020-08-30 14:12:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,263 bytes
コンパイル時間 4,024 ms
コンパイル使用メモリ 263,144 KB
実行使用メモリ 18,984 KB
最終ジャッジ日時 2023-08-09 12:20:08
合計ジャッジ時間 39,519 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 981 ms
11,164 KB
testcase_14 AC 1,119 ms
13,844 KB
testcase_15 AC 1,190 ms
13,600 KB
testcase_16 TLE -
testcase_17 AC 137 ms
4,380 KB
testcase_18 AC 1,143 ms
12,392 KB
testcase_19 AC 158 ms
4,664 KB
testcase_20 AC 179 ms
4,832 KB
testcase_21 AC 179 ms
4,964 KB
testcase_22 AC 1,018 ms
11,612 KB
testcase_23 AC 1,083 ms
13,156 KB
testcase_24 AC 624 ms
8,868 KB
testcase_25 AC 30 ms
4,376 KB
testcase_26 AC 1,293 ms
14,400 KB
testcase_27 AC 665 ms
8,924 KB
testcase_28 AC 1,419 ms
14,892 KB
testcase_29 AC 1,078 ms
12,460 KB
testcase_30 AC 1,386 ms
15,140 KB
testcase_31 AC 606 ms
7,992 KB
testcase_32 AC 1,773 ms
17,240 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 AC 1,871 ms
18,688 KB
testcase_37 AC 1,942 ms
18,820 KB
testcase_38 AC 1,853 ms
18,672 KB
testcase_39 AC 1,881 ms
18,820 KB
testcase_40 AC 1,563 ms
18,816 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 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