結果
問題 | No.771 しおり |
ユーザー |
|
提出日時 | 2023-02-10 12:07:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 204 ms / 2,000 ms |
コード長 | 1,321 bytes |
コンパイル時間 | 984 ms |
コンパイル使用メモリ | 89,236 KB |
実行使用メモリ | 30,000 KB |
最終ジャッジ日時 | 2024-07-07 08:05:42 |
合計ジャッジ時間 | 4,353 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
#include <iostream>#include <vector>#include <string>#include <set>#include <map>#include <algorithm>#include <numeric>#include <queue>#include <cassert>#include <cmath>#include <bitset>using namespace std;void chmin(int &a, int b) {a = min(a, b);}void chmax(int &a, int b) {a = max(a, b);}int main() {int n;cin >> n;vector<int> a(n), b(n);for (int i = 0; i < n; i++) cin >> a[i] >> b[i];vector<vector<int>> d(n, vector<int>(n));for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)d[i][j] = b[i] + a[j] - a[i];//for (int i = 0; i < n; i++)// for (int j = 0; j < n; j++)// cout << "d[" << i << "][" << j << "] = " << d[i][j] << endl;const int inf = (int)1e9;vector<vector<int>> dp(1<<n, vector<int>(n, inf));for (int s = 0; s < (1<<n); s++)for (int i = 0; i < n; i++)if (s&(1<<i))for (int j = 0; j < n; j++)if (~s&(1<<j)) {int ndp = dp[s][i] == inf ? d[i][j] : max(dp[s][i], d[i][j]);chmin(dp[s+(1<<j)][j], ndp);}//for (int s = 0; s < (1<<n); s++)// for (int i = 0; i < n; i++)// cout << "dp[" << bitset<3>(s) << "][" << i << "] = " << dp[s][i] << endl;int ans = inf;for (int i = 0; i < n; i++) chmin(ans, dp[(1<<n)-1][i]);cout << ans << endl;}