結果

問題 No.1211 円環はお断り
ユーザー m_tsubasam_tsubasa
提出日時 2020-08-30 15:14:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,901 ms / 2,000 ms
コード長 1,106 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 209,020 KB
実行使用メモリ 21,992 KB
最終ジャッジ日時 2023-08-09 13:07:08
合計ジャッジ時間 34,741 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 859 ms
12,792 KB
testcase_14 AC 1,016 ms
16,120 KB
testcase_15 AC 1,103 ms
15,668 KB
testcase_16 AC 1,836 ms
21,556 KB
testcase_17 AC 121 ms
4,632 KB
testcase_18 AC 988 ms
14,488 KB
testcase_19 AC 142 ms
4,908 KB
testcase_20 AC 166 ms
5,344 KB
testcase_21 AC 161 ms
5,336 KB
testcase_22 AC 912 ms
13,420 KB
testcase_23 AC 999 ms
14,968 KB
testcase_24 AC 550 ms
9,940 KB
testcase_25 AC 28 ms
4,380 KB
testcase_26 AC 1,193 ms
16,868 KB
testcase_27 AC 582 ms
9,860 KB
testcase_28 AC 1,317 ms
17,136 KB
testcase_29 AC 970 ms
14,260 KB
testcase_30 AC 1,256 ms
17,832 KB
testcase_31 AC 542 ms
9,208 KB
testcase_32 AC 1,597 ms
20,268 KB
testcase_33 AC 1,901 ms
21,796 KB
testcase_34 AC 1,877 ms
21,824 KB
testcase_35 AC 1,871 ms
21,740 KB
testcase_36 AC 1,729 ms
21,920 KB
testcase_37 AC 1,774 ms
21,800 KB
testcase_38 AC 1,682 ms
21,800 KB
testcase_39 AC 1,666 ms
21,796 KB
testcase_40 AC 1,416 ms
21,992 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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() {
  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) {
  vector<long long> memo(n, -1);
  for (long long i = 0, sum = 0, r = 0; i < n; ++i) {
    while (r < 2 * n && sum < x) sum += a[r++];
    memo[i] = r - i;
    sum -= a[i];
  }
  vector<vector<long long>> dp;
  dp.resize(20, vector<long long>(n));
  dp[0] = memo;
  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