結果

問題 No.2890 Chiffon
ユーザー hongrock
提出日時 2024-09-13 22:14:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,307 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 193,620 KB
最終ジャッジ日時 2025-02-24 07:47:21
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define pb emplace_back
#define mp make_pair
 
using ll = long long;
using pii = pair<int,int>;
 
constexpr int mod = 998244353;
constexpr int inf = 0x3f3f3f3f;
constexpr int N = 5e5 + 10;

int n, k, a[N];

bool ok(int st, int d){
  if(st <= 0){
    st = max(st + d, a[1] + 1);
  }
  int cur = st;
  for(int i=2; i<=k; ++i){
    cur += d;
    if(cur < a[i]){
      cur = a[i] + 1;
    } else if(cur > a[i + 1]){
      return 0;
    }
  }
  if(cur + d <= a[k + 1] + 1){
    return 1;
  }
  st = cur + d;
  cur = st - n * 2;
  if(cur > a[2])  return 0;
  for(int i=2; i<=k; ++i){
    cur += d;
    if(cur < a[i]){
      cur = a[i] + 1;
    } else if(cur > a[i + 1]){
      return 0;
    }
  }
  return cur + d <= st;
}

bool ok(int d){
  return ok(a[1] + 1, d) || ok(a[k] + 1 - n * 2, d);
}

void _main(){
  cin >> n >> k;
  for(int i=1; i<=k; ++i) cin >> a[i];
  if(k == 2){
    cout << n << '\n';
    return;
  }
  a[k + 1] = a[1] + n * 2;
  int low = 1, top = n, ans = 1, mid;
  while(low <= top){
    mid = (low + top) >> 1;
    if(ok(mid * 2)){
      ans = max(ans, mid);
      low = mid + 1;
    } else {
      top = mid - 1;
    }
  }
  cout << ans * 2 << '\n';
}

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  _main();
  return 0;
}
0