Submission #2239274


Source Code Expand

//2018年  3月 21日 水曜日 17:17:06 JST
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, MA, MB;
int A[41], B[41], C[41];
ll dp[2][410][410];

void solve() {
	cin >> N >> MA >> MB;
	rep(i, 0, N) {
		cin >> A[i] >> B[i] >> C[i];
	}
	// rep(i, 0, 401) {
	// 	rep(j, 0, 401) {
	// 		dp[0][i][j] = inf;
	// 	}
	// }
	dp[0][0][0] = 0;
	int now = 0, nex = 1;
	rep(i, 0, N) {
		rep(j, 0, 401) {
			rep(k, 0, 401) {
				dp[nex][j][k] = inf;
			}
		}
		rep(j, 0, 401) {
			rep(k, 0, 401) {
				if(dp[now][j][k] == inf) continue;
				MIN(dp[nex][j + A[i]][k + B[i]], dp[now][j][k] + C[i]);
				MIN(dp[nex][j][k], dp[now][j][k]);
			}
		}
		swap(now, nex);
	}
	ll ans = inf;
	rep(i, 0, 15) {
		rep(j, 0, 15) {
			debug(i, j, dp[now][i][j]);
		}
	}
	rep(i, 1, 401) {
		int ma = MB * i, mb = MA * i;
		if(ma > 400 || mb > 400) break;
		MIN(ans, dp[now][ma][mb]);

	}
	if(ans == inf) {
		cout << "-1\n";
	}
	else cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

Submission Info

Submission Time
Task D - Mixing Experiment
User omochana2
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2844 Byte
Status RE
Exec Time 116 ms
Memory 2944 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
WA × 1
RE × 1
WA × 8
RE × 12
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 WA 4 ms 2816 KB
sample_02.txt RE 97 ms 1536 KB
subtask_1_01.txt WA 5 ms 2816 KB
subtask_1_02.txt WA 4 ms 2816 KB
subtask_1_03.txt WA 5 ms 2944 KB
subtask_1_04.txt WA 7 ms 2816 KB
subtask_1_05.txt WA 9 ms 2944 KB
subtask_1_06.txt RE 98 ms 2816 KB
subtask_1_07.txt RE 98 ms 2944 KB
subtask_1_08.txt RE 96 ms 1536 KB
subtask_1_09.txt RE 98 ms 2816 KB
subtask_1_10.txt WA 19 ms 2944 KB
subtask_1_11.txt RE 97 ms 1536 KB
subtask_1_12.txt RE 99 ms 2816 KB
subtask_1_13.txt RE 100 ms 2944 KB
subtask_1_14.txt RE 116 ms 2816 KB
subtask_1_15.txt RE 114 ms 2816 KB
subtask_1_16.txt RE 99 ms 2816 KB
subtask_1_17.txt RE 100 ms 2816 KB
subtask_1_18.txt WA 23 ms 2944 KB