結果

問題 No.2542 Yokan for Two
ユーザー Carpenters-Cat
提出日時 2025-07-04 23:24:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 742 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 203,176 KB
実行使用メモリ 300,544 KB
最終ジャッジ日時 2025-07-04 23:24:56
合計ジャッジ時間 25,490 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 2
other AC * 33 WA * 6 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main () {
	int L, N;
	cin >> L >> N;
	set<int> mp[111][2];
	std::vector<int> A(N);
	for (auto& a : A) cin >> a;
	mp[0][0].insert(A[0]);
	A.push_back(L);
	int pre = A[0];
	int sum = accumulate(A.begin(), A.end(), 0);
	int ans = abs(L - pre * 2);
	for (int i = 1; i <= N; i ++) {
		int x = A[i];
		int d = x - pre;
		for (int p = 0; p < 2; p ++) {
			for (auto& k : mp[i - 1][p]) {
				for (int s = 0; s < 2; s ++) {
					int v = d + k;
					if (s) v = d - k;
					int q = p ^ s;
					if (v + (L - x) <= -ans) continue;
					mp[i][q].insert(v);
					ans = min({ans, abs(v + (L - x))});
				}
			}
		}
		pre = x;
	}
	for (auto k : mp[N][1]) {
		ans = min(ans, abs(k));
	}
	cout << ans << endl;
}
0