Submission #4261224


Source Code Expand

Copy
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll dp[41][401][401];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    
    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N);
    FOR(i, 0, N){
        cin >> A.at(i);
        cin >> B.at(i);
        cin >> C.at(i);
    }
    
    FOR(i, 0, 41){
        FOR(j, 0, 401){
            FOR(k, 0, 401){
                dp[i][j][k] = inf;
            }
        }
    }
    dp[0][0][0] = 0;
    
    FOR(i, 1, N+1){
        // i番目の薬を使うかどうか
        ll a = A[i-1];
        ll b = B[i-1];
        ll c = C[i-1];

        FOR(j, 0, 401){
            FOR(k, 0, 401){
                dp[i][j][k] = dp[i-1][j][k];
                if(j-a>=0 && k-b>=0){
                    dp[i][j][k] = min(dp[i-1][j][k], dp[i-1][j-a][k-b] + c); 
                }
            }
        }
    }

    ll min_cost = inf;

    FOR(i, 1, 401){
        FOR(j, 1, 401){
            if(j * Ma == i * Mb){
                ll cost = dp[N][i][j];
                min_cost = min(min_cost, cost);
            }
        }
    }

    if(min_cost==inf){
        p(-1);
    }else{
        p(min_cost);
    }
    
    return 0;
}

Submission Info

Submission Time
Task D - Mixing Experiment
User peroon
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1812 Byte
Status
Exec Time 25 ms
Memory 51712 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
× 2
× 20
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All sample_01.txt, sample_02.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt
Case Name Status Exec Time Memory
sample_01.txt 15 ms 51712 KB
sample_02.txt 15 ms 51712 KB
subtask_1_01.txt 16 ms 51712 KB
subtask_1_02.txt 15 ms 51712 KB
subtask_1_03.txt 16 ms 51712 KB
subtask_1_04.txt 17 ms 51712 KB
subtask_1_05.txt 18 ms 51712 KB
subtask_1_06.txt 19 ms 51712 KB
subtask_1_07.txt 20 ms 51712 KB
subtask_1_08.txt 21 ms 51712 KB
subtask_1_09.txt 22 ms 51712 KB
subtask_1_10.txt 23 ms 51712 KB
subtask_1_11.txt 25 ms 51712 KB
subtask_1_12.txt 25 ms 51712 KB
subtask_1_13.txt 25 ms 51712 KB
subtask_1_14.txt 25 ms 51712 KB
subtask_1_15.txt 25 ms 51712 KB
subtask_1_16.txt 25 ms 51712 KB
subtask_1_17.txt 25 ms 51712 KB
subtask_1_18.txt 25 ms 51712 KB