結果

問題 No.27 板の準備
ユーザー ttkkggwwttkkggww
提出日時 2022-03-21 17:10:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 802 bytes
コンパイル時間 4,161 ms
コンパイル使用メモリ 260,520 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-30 08:57:28
合計ジャッジ時間 5,763 ms
ジャッジサーバーID
(参考情報)
judge15 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,380 KB
testcase_01 AC 6 ms
4,376 KB
testcase_02 AC 9 ms
4,380 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 15 ms
4,380 KB
testcase_05 AC 15 ms
4,380 KB
testcase_06 AC 18 ms
4,376 KB
testcase_07 AC 17 ms
4,376 KB
testcase_08 AC 20 ms
4,380 KB
testcase_09 AC 18 ms
4,380 KB
testcase_10 AC 14 ms
4,376 KB
testcase_11 AC 14 ms
4,380 KB
testcase_12 AC 16 ms
4,380 KB
testcase_13 AC 13 ms
4,376 KB
testcase_14 AC 11 ms
4,376 KB
testcase_15 AC 13 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 13 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
int n;
vector<int> v;

void solve(){
	vector<int> a(3);
	ll ans = LLONG_MAX/10;
	for(int i = 1;i<=30;i++){
		for(int j = 1;j<=30;j++){
			for(int k = 1;k<=30;k++){
				a = {i,j,k};
				auto minCost = [&](int x){
					vector<int> dp(x+1,1e8);
					dp[0] = 0;
					for(int i = 0;i<x;i++){
						for(int j = 0;j<3;j++){
							if(i+a[j]<=x)
							dp[i+a[j]] = min(dp[i+a[j]],dp[i]+1);
						}
					}
					return dp[x];
				};
				ll cur = 0;
				for(int l = 0;l<4;l++){
					cur += minCost(v[l]);
				}
				ans = min(cur,ans);
			}
		}
	}
	cout<<ans<<endl;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	n = 4;
	v = vector<int>(n);
	for(auto &i:v)cin >> i;
	solve();
}
0