結果
| 問題 |
No.2890 Chiffon
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-18 19:50:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,037 bytes |
| コンパイル時間 | 3,549 ms |
| コンパイル使用メモリ | 189,996 KB |
| 最終ジャッジ日時 | 2025-02-24 09:22:56 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 WA * 11 |
ソースコード
#include<iostream>
#include<sstream>
#include<algorithm>
#include<deque>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<string.h>
#include<string>
#include<math.h>
#include<float.h>
#include<stdio.h>
#include<vector>
#include<iomanip>
#include<bitset>
#include<random>
#include<complex>
#include <cassert>
#include <utility>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T &a, T b) { return ((a>b) ? (a = b, true) : (false));}
#define rep(i,s,n) for(long long i=s;i<(long long)(n);i++)
#define rrep(i,s,n) for(long long i=n-1;i>=s;i--)
const long long inf = 1LL<<60;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//pairのsecondでソートsort(p.begin(),p.end(),cmp)
#define cmp [](pair<ll,ll> a, pair<ll,ll> b){return a.second<b.second;}
//cmpArg := 偏角ソート, atan2l(y, x); atan2l(y, x) = [-pi, pi]
#define cmpArg [](const auto &p1, const auto &p2) { return atan2l(p1.second, p1.first) < atan2l(p2.second, p2.first); }
typedef pair<long long, long long> P;
typedef pair<ll, pair<ll,ll> > PP;
#define rll ll,vector<ll>,greater<ll>
#define rP P,vector<P>,greater<P>
const long double pi = 3.14159265358979;
typedef unsigned long long ull;
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vmint vector<mint>
#define vvmint vector<vector<mint>>
#define vvch vector<vector<char>>
#define vch vector<char>
#define vstring vector<string>
#define rPP PP,vector<PP>,greater<PP>
#define vP vector<P>
#define vvP vector<vector<P>>
#define vPP vector<PP>
#define all(x) x.begin(), x.end()
//UNIQUE(x) xをソートして値の被りがないようにする
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
int pc(ll x) { return __builtin_popcount(x); } //ビット列にどれだけ1がたっているかを求める pop count
//逆順のlower_bound(単調減少関数で自分以下を二分探索)するときは`ll index = lower_bound(all(inv), -a[i], greater<ll>()) - inv.begin();`, 逆からみたlis的なやつが作れる
//オバフロしない計算はa > inf - b および a > inf / bでとってね
//半分全列挙は前の方を(siz+1)/2ででかくする
//using mint = atcoder::modint, main関数でmint::set_mod(M)とすると任意modのmintにできる
//mapでも auto it = mp.lower_bound(key)としてlower_boundが使用できる while(it != mp.end())でループすることもできる
using mint = modint998244353;
int main()
{
int n,k; cin >> n >> k;
//0-indexedで考えるから, a[i]は偶数, b[i]は奇数
vector<int> a(k); rep(i,0,k) cin >> a[i], a[i]--;
set<int> st; rep(i,0,k) st.insert(a[i]);
//二分探索, 最小値K以上で切り分ける方法があるか?
int left = -1, right = 2*n+1;
while(right - left > 1) {
int mid = (left + right) / 2;
//2分探索 mid以上ですべてを切り分けることができるか
vector<bool> dp(4*n+10,false); //条件を達成できるか
dp[*st.begin()+1] = true;
rep(i,*st.begin()+1, *st.rbegin()+1) {
if(!dp[i]) continue;
if(!st.count(i+1)) dp[i+1] = true; //次がイチゴじゃない
int lb = i + mid;
auto nxt = st.lower_bound(i);
lb = max(lb, *nxt+1); //イチゴをまたぐ
auto nnxt = st.upper_bound(*nxt);
int ub;
if(nnxt == st.end()) ub = *st.begin() + 2*n;
else ub = *nnxt;
if(lb >= ub) continue;
dp[lb] = true;
}
auto sec = st.begin(); sec++;
bool can = false;
rep(i,*st.rbegin()+1,*st.begin()+2*n) {
//どれか1つでもtrueがあればOK
if(dp[i] && *sec-i+2*n >= mid) can = true;
}
if(can) left = mid;
else right = mid;
}
cout << left << endl;
}