結果

問題 No.27 板の準備
ユーザー ttkkggww
提出日時 2022-03-21 17:10:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 802 bytes
コンパイル時間 4,260 ms
コンパイル使用メモリ 251,744 KB
最終ジャッジ日時 2025-01-28 10:55:46
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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