結果

問題 No.771 しおり
ユーザー ありあり
提出日時 2023-02-10 12:07:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 1,321 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 29,672 KB
最終ジャッジ日時 2023-09-21 14:19:21
合計ジャッジ時間 6,304 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 208 ms
29,544 KB
testcase_01 AC 22 ms
6,432 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 98 ms
16,276 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 22 ms
6,412 KB
testcase_28 AC 46 ms
9,616 KB
testcase_29 AC 23 ms
6,424 KB
testcase_30 AC 208 ms
29,520 KB
testcase_31 AC 208 ms
29,536 KB
testcase_32 AC 6 ms
4,380 KB
testcase_33 AC 209 ms
29,576 KB
testcase_34 AC 209 ms
29,668 KB
testcase_35 AC 6 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 6 ms
4,376 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 98 ms
16,344 KB
testcase_41 AC 208 ms
29,672 KB
testcase_42 AC 209 ms
29,544 KB
testcase_43 AC 23 ms
6,428 KB
testcase_44 AC 209 ms
29,668 KB
testcase_45 AC 209 ms
29,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0