結果

問題 No.2542 Yokan for Two
ユーザー k82b
提出日時 2023-11-24 21:55:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 386 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 193,320 KB
最終ジャッジ日時 2025-02-18 00:03:02
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int=long long;
using Real=long double;
template<class T>inline bool chmin(T&A,T B){return(A>B?A=B,1:0);}
template<class T>inline bool chmax(T&A,T B){return(A<B?A=B,1:0);}
#define REP(i,n)for(int i=0;i<(n);++i)
#define REP1(i,n)for(int i=1;i<=(n);++i)
#define ALL(x)begin(x),end(x)
#define drop(x){cout<<x<<'\n';return;}
const int MOD=998244353;
int L,N;
int X[200],A[200];
bool dp[2][3<<17][2][2];
int zero=(3<<17)/2;
void sol()
{
	cin>>L>>N;
	REP(i,N)
	{
		cin>>X[i+1];
		A[i]=X[i+1]-X[i];
	}
	A[N]=L-X[N];
	int now=0;
	dp[now][zero-A[0]][0][0]=dp[now][zero+A[0]][1][0]=true;
	REP1(i,N)
	{
		int nxt=!now;
		REP(j,3<<17)REP(k,2)REP(l,2)dp[nxt][j][k][l]=false;
		REP(j,3<<17)REP(k,2)REP(l,2)
		{
			if(j-A[i]>=0)
			{
				dp[nxt][j-A[i]][0][(l+(k==1))%2]|=dp[now][j][k][l];
			}
			if(j+A[i]<3<<17)
			{
				dp[nxt][j+A[i]][1][(l+(k==0))%2]|=dp[now][j][k][l];
			}
		}
		now=nxt;
	}
	REP(i,1e9)
	{
		bool ok=false;
		REP(j,2)ok=ok||dp[now][zero-i][j][1]||dp[now][zero+i][j][1];
		if(ok)drop(i);
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout<<fixed<<setprecision(16);
	int T=1;
	//cin>>T;
	while(T--)sol();
}
0