結果
| 問題 | No.771 しおり | 
| コンテスト | |
| ユーザー |  tnakao0123 | 
| 提出日時 | 2018-12-26 10:39:13 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 285 ms / 2,000 ms | 
| コード長 | 1,287 bytes | 
| コンパイル時間 | 644 ms | 
| コンパイル使用メモリ | 86,708 KB | 
| 実行使用メモリ | 22,100 KB | 
| 最終ジャッジ日時 | 2024-07-22 07:08:20 | 
| 合計ジャッジ時間 | 4,962 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 43 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:49:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   49 |   for (int i = 0; i < n; i++) scanf("%d%d", as + i, bs + i);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
            
            ソースコード
/* -*- 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;
}
            
            
            
        