Submission #1104866
Source Code Expand
#include <iostream> #include <iomanip> // << fixed << setprecision(xxx) #include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ; #include <vector> #include <string> // to_string(nnn) // substr(m, n) // stoi(nnn) #include <complex> #include <tuple> // get<n>(xxx) #include <queue> #include <stack> #include <map> // if (M.find(key) != M.end()) { } #include <set> // S.insert(M); // if (S.find(key) != S.end()) { } // for (auto it=S.begin(); it != S.end(); it++) { } // auto it = S.lower_bound(M); #include <cctype> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> // atoi(xxx) using namespace std; #define DEBUG 0 // change 0 -> 1 if we need debug. // insert #if<tab> by my emacs. #if DEBUG == 1 ... #end typedef long long ll; // const int dx[4] = {1, 0, -1, 0}; // const int dy[4] = {0, 1, 0, -1}; const int C = 410; const int infty = 1000000007; int N, Ma, Mb; int a[100], b[100], c[100]; int DP[410][410]; int main () { cin >> N >> Ma >> Mb; for (auto i = 0; i < N; ++i) { cin >> a[i] >> b[i] >> c[i]; } for (auto i = 0; i < C; ++i) { for (auto j = 0; j < C; ++j) { DP[i][j] = infty; } } DP[0][0] = 0; for (auto t = 0; t < N; ++t) { for (auto i = C-1; i >= 0; --i) { for (auto j = C-1; j >= 0; --j) { if (DP[i][j] < infty) { int newi = i + a[t]; int newj = j + b[t]; if (newi < C && newj < C) { DP[newi][newj] = min(DP[newi][newj], DP[i][j] + c[t]); } } } } } int ans = infty; for (auto i = 1; i < C; ++i) { for (auto j = 1; j < C; ++j) { if (i * Mb == j * Ma) { ans = min(ans, DP[i][j]); } } } for (auto i = 0; i < 40; ++i) { for (auto j = 0; j < 40; ++j) { cerr << DP[i][j] << " "; } cerr << endl; } if (ans == infty) { cout << -1 << endl; } else { cout << ans << endl; } }
Submission Info
Submission Time | |
---|---|
Task | D - Mixing Experiment |
User | kazunetakahashi |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1996 Byte |
Status | AC |
Exec Time | 8 ms |
Memory | 896 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
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 | AC | 3 ms | 896 KB |
sample_02.txt | AC | 3 ms | 896 KB |
subtask_1_01.txt | AC | 4 ms | 896 KB |
subtask_1_02.txt | AC | 3 ms | 896 KB |
subtask_1_03.txt | AC | 4 ms | 896 KB |
subtask_1_04.txt | AC | 4 ms | 896 KB |
subtask_1_05.txt | AC | 4 ms | 896 KB |
subtask_1_06.txt | AC | 5 ms | 896 KB |
subtask_1_07.txt | AC | 6 ms | 896 KB |
subtask_1_08.txt | AC | 6 ms | 896 KB |
subtask_1_09.txt | AC | 6 ms | 896 KB |
subtask_1_10.txt | AC | 7 ms | 896 KB |
subtask_1_11.txt | AC | 8 ms | 896 KB |
subtask_1_12.txt | AC | 8 ms | 896 KB |
subtask_1_13.txt | AC | 8 ms | 896 KB |
subtask_1_14.txt | AC | 8 ms | 896 KB |
subtask_1_15.txt | AC | 8 ms | 896 KB |
subtask_1_16.txt | AC | 8 ms | 896 KB |
subtask_1_17.txt | AC | 8 ms | 896 KB |
subtask_1_18.txt | AC | 8 ms | 896 KB |