結果

問題 No.27 板の準備
ユーザー 0w10w1
提出日時 2016-12-04 16:37:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,576 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 170,928 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 04:37:40
合計ジャッジ時間 2,420 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 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,380 KB
testcase_17 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef vector< pii > vp;
typedef vector< vp > vvp;
typedef vector< string > vs;
typedef vector< double > vd;
typedef vector< vd > vvd;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

vi V;

void init(){
  V = vi( 4 );
  for( int i = 0; i < 4; ++i )
    cin >> V[ i ];
}

void preprocess(){
  sort( V.begin(), V.end() );
}

void solve(){
  int ans = 1e9;
  for( int i = 1; i <= V[ 0 ]; ++i )
    for( int j = i; j <= V[ 3 ]; ++j )
      for( int k = j; k <= V[ 3 ]; ++k ){
        vi dp( V[ 3 ] + 1, 0x3f3f3f3f );
        dp[ 0 ] = 0;
        for( int l = 0; l < V[ 3 ]; ++l ){
          if( l + i <= V[ 3 ] )
            upmin( dp[ l + i ], dp[ l ] + 1 );
          if( l + j <= V[ 3 ] )
            upmin( dp[ l + j ], dp[ l ] + 1 );
          if( l + k <= V[ 3 ] )
            upmin( dp[ l + k ], dp[ l ] + 1 );
        }
        int cost = 0;
        for( int l = 0; l < 4; ++l ){
          if( dp[ V[ l ] ] == 0x3f3f3f3f ){
            cost = 0x3f3f3f3f;
            break;
          }
          cost += dp[ V[ l ] ];
        }
        upmin( ans, cost );
      }
  cout << ans << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0