結果

問題 No.1211 円環はお断り
ユーザー m_tsubasam_tsubasa
提出日時 2020-08-30 15:15:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,285 ms / 2,000 ms
コード長 1,056 bytes
コンパイル時間 2,057 ms
コンパイル使用メモリ 209,144 KB
実行使用メモリ 21,124 KB
最終ジャッジ日時 2023-08-15 10:01:47
合計ジャッジ時間 23,787 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 581 ms
12,300 KB
testcase_14 AC 631 ms
15,444 KB
testcase_15 AC 745 ms
15,452 KB
testcase_16 AC 1,230 ms
20,740 KB
testcase_17 AC 90 ms
4,580 KB
testcase_18 AC 688 ms
13,920 KB
testcase_19 AC 102 ms
4,928 KB
testcase_20 AC 119 ms
5,272 KB
testcase_21 AC 113 ms
5,104 KB
testcase_22 AC 622 ms
12,860 KB
testcase_23 AC 646 ms
14,396 KB
testcase_24 AC 368 ms
9,708 KB
testcase_25 AC 22 ms
4,380 KB
testcase_26 AC 769 ms
16,240 KB
testcase_27 AC 397 ms
9,640 KB
testcase_28 AC 862 ms
16,456 KB
testcase_29 AC 632 ms
13,604 KB
testcase_30 AC 814 ms
17,032 KB
testcase_31 AC 375 ms
9,140 KB
testcase_32 AC 1,053 ms
19,404 KB
testcase_33 AC 1,285 ms
21,016 KB
testcase_34 AC 1,243 ms
21,124 KB
testcase_35 AC 1,242 ms
20,996 KB
testcase_36 AC 1,111 ms
21,048 KB
testcase_37 AC 1,189 ms
20,944 KB
testcase_38 AC 1,059 ms
20,992 KB
testcase_39 AC 1,061 ms
20,944 KB
testcase_40 AC 796 ms
21,048 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int n, k;
vector<long long> a;
vector<vector<long long>> dp;

long long solve();
bool ch(long long x);

int main() {
  cin >> n >> k;
  a.resize(2 * n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i + n] = a[i];
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  dp.resize(20, vector<long long>(n));
  long long l = 0, r = 1;
  for (int i = 0; i < n; ++i) r += a[i];
  while (r - l > 1) {
    long long mid = (l + r) >> 1;
    if (ch(mid))
      l = mid;
    else
      r = mid;
  }
  return l;
}
bool ch(long long x) {
  for (long long i = 0, sum = 0, r = 0; i < n; ++i) {
    while (r < 2 * n && sum < x) sum += a[r++];
    dp[0][i] = r - i;
    sum -= a[i];
  }
  for (int i = 1; i <= 17; ++i)
    for (int j = 0; j < n; ++j)
      dp[i][j] = dp[i - 1][j] + dp[i - 1][(j + dp[i - 1][j]) % n];
  for (int i = 0; i < n; ++i) {
    long long cnt = 0;
    for (int j = 0; j <= 17; ++j)
      if (k >> j & 1) cnt += dp[j][(i + cnt) % n];
    if (cnt <= n) return 1;
  }
  return 0;
}
0