結果
| 問題 |
No.2890 Chiffon
|
| コンテスト | |
| ユーザー |
hongrock
|
| 提出日時 | 2024-09-13 22:21:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 2,000 ms |
| コード長 | 1,196 bytes |
| コンパイル時間 | 2,006 ms |
| コンパイル使用メモリ | 193,252 KB |
| 最終ジャッジ日時 | 2025-02-24 07:51:24 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 53 |
ソースコード
#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 d){
int cur = a[1] + 1;
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;
}
int 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;
}
void _main(){
cin >> n >> k;
for(int i=1; i<=k; ++i) cin >> a[i];
if(k == 2){
cout << n - (n & 1) << '\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;
}
hongrock