結果

問題 No.2890 Chiffon
ユーザー haihamabossuhaihamabossu
提出日時 2024-09-13 23:30:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,583 bytes
コンパイル時間 2,400 ms
コンパイル使用メモリ 203,932 KB
実行使用メモリ 15,016 KB
最終ジャッジ日時 2024-09-13 23:30:49
合計ジャッジ時間 4,898 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 64 ms
15,016 KB
testcase_23 AC 5 ms
7,536 KB
testcase_24 AC 5 ms
6,528 KB
testcase_25 AC 5 ms
9,728 KB
testcase_26 AC 6 ms
10,240 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 6 ms
6,912 KB
testcase_30 AC 7 ms
10,752 KB
testcase_31 AC 6 ms
9,856 KB
testcase_32 AC 3 ms
5,376 KB
testcase_33 AC 31 ms
12,664 KB
testcase_34 AC 30 ms
12,556 KB
testcase_35 AC 30 ms
12,540 KB
testcase_36 AC 30 ms
12,664 KB
testcase_37 AC 30 ms
12,564 KB
testcase_38 AC 29 ms
12,560 KB
testcase_39 AC 31 ms
12,656 KB
testcase_40 AC 29 ms
12,552 KB
testcase_41 AC 30 ms
12,672 KB
testcase_42 AC 30 ms
12,536 KB
testcase_43 AC 31 ms
12,616 KB
testcase_44 AC 31 ms
12,660 KB
testcase_45 AC 33 ms
12,564 KB
testcase_46 AC 35 ms
12,480 KB
testcase_47 AC 32 ms
12,544 KB
testcase_48 AC 32 ms
12,668 KB
testcase_49 AC 31 ms
12,640 KB
testcase_50 AC 32 ms
12,568 KB
testcase_51 AC 32 ms
12,644 KB
testcase_52 AC 31 ms
12,540 KB
testcase_53 AC 23 ms
10,880 KB
testcase_54 AC 24 ms
12,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

void solve() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(k);
  rep(i, k) cin >> a[i];
  {
    vector<ll> na(k);
    ll min_d = 1e18, min_i = -1;
    rep(i, k) {
      ll d = a[(i + 1) % k] - a[i];
      if (i == k - 1)
        d += n * 2;
      if (d < min_d) {
        min_d = d;
        min_i = i;
      }
    }
    ll x = a[min_i] - 1;
    rep(i, k) {
      ll j = (i + min_i) % k;
      na[i] = a[j] - x;
      if (j < min_i)
        na[i] += n * 2;
    }
    swap(a, na);
  }
  vector<ll> sum(n * 2 + 10, 0);
  {
    ll j = 0;
    rep(i, n * 2 + 5) {
      sum[i + 1] = sum[i];
      if (j < k && a[j] == i + 1) {
        sum[i + 1]++;
        j++;
      }
    }
  }
  ll ans = -1;
  for (ll s = 2; s < a[1]; s += 2) {
    ll L = 2, R = n + 1;
    while (L + 1 < R) {
      ll w = (L + R) / 2, now = s;
      bool ok = true;
      rep(i, k - 1) {
        ll nex = max(now + w, a[i + 1] + 1);
        if (nex > n * 2) {
          ok = false;
          break;
        }
        ok &= sum[nex] - sum[now] == 1;
        if (!ok)
          break;
        now = nex;
      }
      ok &= sum[n * 2 + 1] - sum[now] == 0;
      ok &= n * 2 - now + s >= w;
      if (ok) {
        L = w;
      } else {
        R = w;
      }
    }
    ans = max(ans, L);
  }
  if (ans % 2)
    ans--;
  cout << ans << '\n';
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int T = 1;
  for (int t = 0; t < T; t++) {
    solve();
  }
  return 0;
}
0