AtCoder Beginner Contest 054

Submission #1588647

Source codeソースコード

#include <bits/stdc++.h>
#include <regex>
using namespace std;
typedef long long ll;

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MAX_V 100000

#define MOD 1000000007L
#define INF 100000000000

signed main() {
	int n, ma, mb;
	cin >> n >> ma >> mb;
	map<tuple<int, int>, int> map = {}, nmap = {};
	map[make_tuple(0, 0)] = 0;
	for (size_t i = 0; i < n ; i++) {
		nmap = {};
		int a, b, c;
		cin >> a >> b >> c;
		for (const auto& itr: map) {
			int ao = get<0>(itr.first);
			int bo = get<1>(itr.first);
			if (itr.second < nmap[make_tuple(ao, bo)]) {
				nmap[make_tuple(ao, bo)] = itr.second;
			}
			int tn = nmap[make_tuple(ao + a, bo + b)];
			if (tn < itr.second + c) {
				nmap[make_tuple(ao + a, bo + b)] = itr.second + c;
			}
		}
		map = nmap;
	}
	int m = -1;
	for (const auto& itr: map) {
		int ao = get<0>(itr.first);
		int bo = get<1>(itr.first);
		if (ao + bo == 0) {
			continue;
		}
		if (ao * mb == bo * ma) {
			if (m == -1) {
				m = itr.second;
			}
			m = m == -1 ? itr.second : min(m, itr.second);
		}
		// printf("%d, %d = %d\n", ao, bo, itr.second);
	}
	cout << m << endl;
}

Submission

Task問題 D - Mixing Experiment
User nameユーザ名 えるざっぷ
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 1368 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt
All 0 / 400 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
subtask_1_01.txt AC 1 ms 256 KB
subtask_1_02.txt AC 1 ms 256 KB
subtask_1_03.txt AC 1 ms 256 KB
subtask_1_04.txt AC 1 ms 256 KB
subtask_1_05.txt WA
subtask_1_06.txt WA
subtask_1_07.txt WA
subtask_1_08.txt WA
subtask_1_09.txt WA
subtask_1_10.txt WA
subtask_1_11.txt WA
subtask_1_12.txt WA
subtask_1_13.txt WA
subtask_1_14.txt WA
subtask_1_15.txt WA
subtask_1_16.txt WA
subtask_1_17.txt WA
subtask_1_18.txt WA