Contest Duration: ~ (local time) (100 minutes) Back to Home

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 2019-02-14 19:43:32+0900 D - Mixing Experiment peroon C++14 (GCC 5.4.1) 400 1812 Byte AC 25 ms 51712 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
 AC × 2
 AC × 20
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
sample_01.txt 15 ms 51712 KB
sample_02.txt 15 ms 51712 KB