結果
| 問題 |
No.2542 Yokan for Two
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-11-25 10:17:21 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,415 ms / 2,000 ms |
| コード長 | 1,091 bytes |
| コンパイル時間 | 5,726 ms |
| コンパイル使用メモリ | 315,272 KB |
| 実行使用メモリ | 12,032 KB |
| 最終ジャッジ日時 | 2024-09-26 10:15:10 |
| 合計ジャッジ時間 | 30,344 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
template <class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int INF = INT_MAX / 2;
const ll LINF = 1LL << 60;
const vector<int> dx = {-1, 0, 1, 0}, dy = {0, 1, 0, -1};
using mint = modint998244353;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int l, n;
cin >> l >> n;
vector<int> x(n);
for (int i = 0; i < n; i++) {
cin >> x[i];
}
map<int, int> mp;
mp[x[0]] = 1;
for (int i = 1; i < n; i++) {
map<int, int> mp2;
for (int j = -(int)1e5; j <= (int)1e5; j++) {
if (mp.count(j)) {
mp2[j + x[i] - x[i - 1]] = 1;
mp2[j - (x[i] - x[i - 1])] = 1;
}
}
swap(mp, mp2);
}
int ans = INF;
for (int i = -(int)1e5; i <= (int)1e5; i++) {
if (mp.count(i)) {
chmin(ans, abs(i - (l - x[n - 1])));
}
}
cout << ans << '\n';
return 0;
}