結果

問題 No.2890 Chiffon
ユーザー Kude
提出日時 2024-09-13 22:10:14
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,641 bytes
コンパイル時間 3,576 ms
コンパイル使用メモリ 273,296 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-09-26 14:40:50
合計ジャッジ時間 6,488 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  VI a(n);
  rep(_, k) {
    int x;
    cin >> x;
    x = (x - 1) / 2;
    a[x] = 1;
  }
  rotate(a.begin(), find(all(a), 1) + 1, a.end());
  VI s(n + 1);
  rep(i, n) s[i+1] = s[i] + a[i];
  VI nxt(n+1, -1);
  rrep(i, n) nxt[i] = a[i] ? i : nxt[i+1];
  int l = 0, r = n / 2 + 1;
  VI to(n + 1);
  while (r - l > 1) {
    int c = (l + r) / 2;
    rrep(i, n + 1) {
      to[i] = [&]() {
        if (i + c <= n) {
          if (s[i+c] - s[i] == 1) return to[i+c];
          if (s[i+c] - s[i] == 0 && nxt[i] != -1) return to[nxt[i]+1];
        }
        return i;
      }(); 
    }
    bool ok = false;
    rep(i, n) {
      int j = to[i];
      if (s[n] - s[j] == 0) ok = true;
      else if (s[n] - s[j] == 1 && n - j + i >= c) ok = true;
      if (a[i]) break;
    }
    (ok ? l : r) = c;
  }
  cout << l * 2 << '\n';
}
0