Submission #1103888


Source Code Expand

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

int as[50], bs[50], cs[50];
int tbl1[410][410], tbl2[410][410];

const int INF = 1010101010;

void calc(int from, int to, int tbl[][410]){
	for(int i = 0; i < 410; ++i)
	for(int j = 0; j < 410; ++j){
		tbl[i][j] = INF;
	}
	
	tbl[0][0] = 0;
	for(int i = from; i < to; ++i){
		for(int j = 400; j >= as[i]; --j)
		for(int k = 400; k >= bs[i]; --k){
			tbl[j][k] = min(tbl[j][k], tbl[j - as[i]][k - bs[i]] + cs[i]);
		}
	}
}

void mainmain(){
	int n, ma, mb;
	cin >> n >> ma >> mb;
	for(int i = 0; i < n; ++i){
		cin >> as[i] >> bs[i] >> cs[i];
	}
	
	calc(0, n / 2, tbl1);
	calc(n / 2, n, tbl2);
	
	int ans = INF;
	for(int w = 0; w <= 400; ++w)
	for(int x = 0; x <= 400; ++x)
	for(int y = 0; y <= 400; ++y){
		int t = (w + y) * mb;
		if(t % ma == 0){
			int z = t / ma - x;
			if(0 <= z && z <= 400){
				if(!w && !x && !y && !z){ continue; }
				ans = min(ans, tbl1[w][x] + tbl2[y][z]);
			}
		}
	}
	
	if(ans == INF){ ans = -1; }
	cout << ans << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}

Submission Info

Submission Time
Task D - Mixing Experiment
User climpet
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2665 Byte
Status AC
Exec Time 285 ms
Memory 1536 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
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 278 ms 1536 KB
sample_02.txt AC 234 ms 1536 KB
subtask_1_01.txt AC 223 ms 1536 KB
subtask_1_02.txt AC 227 ms 1536 KB
subtask_1_03.txt AC 235 ms 1536 KB
subtask_1_04.txt AC 224 ms 1536 KB
subtask_1_05.txt AC 225 ms 1536 KB
subtask_1_06.txt AC 225 ms 1536 KB
subtask_1_07.txt AC 232 ms 1536 KB
subtask_1_08.txt AC 233 ms 1536 KB
subtask_1_09.txt AC 243 ms 1536 KB
subtask_1_10.txt AC 239 ms 1536 KB
subtask_1_11.txt AC 229 ms 1536 KB
subtask_1_12.txt AC 285 ms 1536 KB
subtask_1_13.txt AC 231 ms 1536 KB
subtask_1_14.txt AC 229 ms 1536 KB
subtask_1_15.txt AC 227 ms 1536 KB
subtask_1_16.txt AC 230 ms 1536 KB
subtask_1_17.txt AC 225 ms 1536 KB
subtask_1_18.txt AC 229 ms 1536 KB