結果
| 問題 |
No.771 しおり
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-02 16:48:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,547 ms / 2,000 ms |
| コード長 | 1,484 bytes |
| コンパイル時間 | 1,271 ms |
| コンパイル使用メモリ | 86,172 KB |
| 最終ジャッジ日時 | 2025-01-12 13:27:30 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
void solve() {
int n;
std::cin >> n;
std::vector<std::pair<int, int>> ps(n);
for (auto& p : ps) {
int a, b;
std::cin >> a >> b;
p = std::make_pair(a, b - a);
}
int ok = 2000, ng = 0;
while (ok - ng > 1) {
int mid = (ok + ng) / 2;
std::vector<std::vector<int>> graph(n);
for (int v = 0; v < n; ++v) {
for (int u = 0; u < n; ++u) {
if (u == v || ps[v].second + ps[u].first > mid) continue;
graph[v].push_back(u);
}
}
auto dp = vec(n, vec(1 << n, false));
for (int i = 0; i < n; ++i) {
dp[i][1 << i] = true;
}
for (int b = 0; b < (1 << n); ++b) {
for (int i = 0; i < n; ++i) {
if (!dp[i][b]) continue;
for (auto j : graph[i]) {
if ((b >> j) & 1) continue;
dp[j][b | (1 << j)] = true;
}
}
}
if (std::any_of(dp.begin(), dp.end(),
[](const auto& v) { return v.back(); })) {
ok = mid;
} else {
ng = mid;
}
}
std::cout << ok << "\n";
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}