結果

問題 No.1211 円環はお断り
ユーザー tnakao0123tnakao0123
提出日時 2020-08-31 16:16:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,692 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 91,084 KB
実行使用メモリ 18,548 KB
最終ジャッジ日時 2023-08-10 03:05:23
合計ジャッジ時間 16,557 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,596 KB
testcase_01 AC 3 ms
5,732 KB
testcase_02 WA -
testcase_03 AC 2 ms
5,512 KB
testcase_04 AC 2 ms
5,580 KB
testcase_05 AC 2 ms
5,828 KB
testcase_06 AC 2 ms
5,528 KB
testcase_07 WA -
testcase_08 AC 2 ms
5,584 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 434 ms
16,152 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 359 ms
16,200 KB
testcase_19 WA -
testcase_20 AC 54 ms
7,224 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 494 ms
16,072 KB
testcase_27 WA -
testcase_28 AC 526 ms
18,248 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 AC 2 ms
5,516 KB
testcase_42 AC 2 ms
5,588 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][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++];
    if (sum < m) ps[i][0] = INF;
    else ps[i][0] = j;
    sum -= as[i];
  }

  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 >= INF) break;
    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