結果

問題 No.27 板の準備
コンテスト
ユーザー pessimist
提出日時 2026-01-18 06:55:56
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,032 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,164 ms
コンパイル使用メモリ 355,972 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-01-18 06:56:03
合計ジャッジ時間 5,664 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
const int INF=1e9;
void solve(){
    int arr[4];
    for(int i=0;i<4;++i)cin>>arr[i];
    auto solve=[&] (int a,int b,int c){
        vector dp(31,INF);
        dp[0]=0;
        for(auto&val:vector<int>({a,b,c})){
            for(int n=0;n<31-val;++n){
                dp[n+val]=min(dp[n+val],dp[n]+1);
            }
        }
        ll ret=0;
        for(int i=0;i<4;++i)ret+=dp[arr[i]];
        return ret;
    };
    ll ans=INF;
    auto r=views::iota(1,31);
    for(auto [a,b,c]: std::views::cartesian_product(r,r,r) | 
            std::views::filter([](auto t){
                auto [a,b,c]=t;
                return a<b&&b<c;
            })){
        ll tans=solve(a,b,c);
        ans=min(ans,tans);
    }
    cout<<ans<<endl;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int T=1; //cin>>T;
    while(T--)solve();
    return 0;
}
0