結果

問題 No.1211 円環はお断り
ユーザー tnakao0123tnakao0123
提出日時 2020-08-31 17:11:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 711 ms / 2,000 ms
コード長 1,672 bytes
コンパイル時間 883 ms
コンパイル使用メモリ 91,960 KB
実行使用メモリ 18,520 KB
最終ジャッジ日時 2023-08-15 10:20:11
合計ジャッジ時間 14,160 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,580 KB
testcase_01 AC 2 ms
5,524 KB
testcase_02 AC 2 ms
5,564 KB
testcase_03 AC 2 ms
5,496 KB
testcase_04 AC 2 ms
5,572 KB
testcase_05 AC 2 ms
5,560 KB
testcase_06 AC 2 ms
5,508 KB
testcase_07 AC 3 ms
5,764 KB
testcase_08 AC 2 ms
5,556 KB
testcase_09 AC 2 ms
5,536 KB
testcase_10 AC 2 ms
5,504 KB
testcase_11 AC 2 ms
5,524 KB
testcase_12 AC 2 ms
5,564 KB
testcase_13 AC 316 ms
13,816 KB
testcase_14 AC 458 ms
16,148 KB
testcase_15 AC 449 ms
16,088 KB
testcase_16 AC 694 ms
18,352 KB
testcase_17 AC 38 ms
6,748 KB
testcase_18 AC 363 ms
16,196 KB
testcase_19 AC 37 ms
6,912 KB
testcase_20 AC 55 ms
7,128 KB
testcase_21 AC 52 ms
7,180 KB
testcase_22 AC 331 ms
13,916 KB
testcase_23 AC 382 ms
15,968 KB
testcase_24 AC 206 ms
11,900 KB
testcase_25 AC 8 ms
5,928 KB
testcase_26 AC 486 ms
16,128 KB
testcase_27 AC 212 ms
11,720 KB
testcase_28 AC 509 ms
18,116 KB
testcase_29 AC 359 ms
16,000 KB
testcase_30 AC 504 ms
18,252 KB
testcase_31 AC 170 ms
11,724 KB
testcase_32 AC 615 ms
18,240 KB
testcase_33 AC 711 ms
18,316 KB
testcase_34 AC 693 ms
18,304 KB
testcase_35 AC 696 ms
18,428 KB
testcase_36 AC 701 ms
18,280 KB
testcase_37 AC 707 ms
18,300 KB
testcase_38 AC 667 ms
18,280 KB
testcase_39 AC 681 ms
18,384 KB
testcase_40 AC 578 ms
18,520 KB
testcase_41 AC 2 ms
5,596 KB
testcase_42 AC 2 ms
5,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1211.cc:  No.1211 円環はお断り - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_N2 = MAX_N * 2;
const int BN = 18;
const int INF = 1 << 30;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N2], ps[MAX_N2 + 1][BN];

/* subroutines */

bool check(int n, int k, int bn, ll m) {
  int n2 = n * 2;
  ll sum = 0;
  for (int i = 0, j = 0; i < n2; i++) {
    while (j < n2 && sum < m) sum += as[j++];
    ps[i][0] = (sum >= m) ? j : INF;
    sum -= as[i];
  }
  ps[n2][0] = INF;

  for (int b = 0; b + 1 < bn; b++)
    for (int i = 0; i <= n2; i++)
      ps[i][b + 1] = (ps[i][b] < INF) ? ps[ps[i][b]][b] : INF;

  for (int i = 0; i < n; i++) {
    int j = i;
    for (int b = bn - 1; b >= 0 && j < INF; b--)
      if ((k >> b) & 1) j = ps[j][b];
    if (j - i <= n) return true;
  }

  return false;
}

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int n2 = n * 2;

  ll asum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", as + i), as[n + i] = as[i];
    asum += as[i];
  }

  int bn = 0;
  for (int bi = 1; bi <= n2; bn++, bi <<= 1);
  //printf("bn=%d\n", bn);

  ll m0 = 1, m1 = asum + 1;
  while (m0 + 1 < m1) {
    ll m = (m0 + m1) / 2;
    if (check(n, k, bn, m)) m0 = m;
    else m1 = m;
  }

  printf("%lld\n", m0);
  return 0;
}
0