結果

問題 No.771 しおり
ユーザー tnakao0123tnakao0123
提出日時 2018-12-26 10:39:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 1,287 bytes
コンパイル時間 577 ms
コンパイル使用メモリ 83,048 KB
実行使用メモリ 21,996 KB
最終ジャッジ日時 2023-09-29 12:49:31
合計ジャッジ時間 4,005 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 201 ms
21,952 KB
testcase_01 AC 19 ms
7,516 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 89 ms
13,752 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 21 ms
7,580 KB
testcase_28 AC 46 ms
9,684 KB
testcase_29 AC 21 ms
7,516 KB
testcase_30 AC 198 ms
21,852 KB
testcase_31 AC 199 ms
21,916 KB
testcase_32 AC 6 ms
4,376 KB
testcase_33 AC 196 ms
21,996 KB
testcase_34 AC 187 ms
21,908 KB
testcase_35 AC 6 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,384 KB
testcase_38 AC 5 ms
4,380 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 86 ms
13,900 KB
testcase_41 AC 189 ms
21,848 KB
testcase_42 AC 175 ms
21,904 KB
testcase_43 AC 22 ms
7,496 KB
testcase_44 AC 180 ms
21,960 KB
testcase_45 AC 203 ms
21,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 771.cc:  No.771 しおり - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 18;
const int NBITS = 1 << MAX_N;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N];
int dp[NBITS][MAX_N];

/* subroutines */

inline void setmin(int &a, int b) { if (a > b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d%d", as + i, bs + i);

  int nbits = 1 << n;
  for (int bits = 0; bits < nbits; bits++)
    fill(dp[bits], dp[bits] + n, INF);
  for (int i = 0, bi = 1; i < n; i++, bi <<= 1) dp[bi][i] = 0;

  for (int bits = 1; bits < nbits; bits++)
    for (int i = 0; i < n; i++)
      for (int j = 0, bj = 1; j < n; j++, bj <<= 1)
	if (! (bits & bj))
	  setmin(dp[bits | bj][j], max(dp[bits][i], bs[i] - as[i] + as[j]));

  int mind = INF;
  for (int i = 0; i < n; i++)
    setmin(mind, dp[nbits - 1][i]);
  printf("%d\n", mind);
  return 0;
}
0