AtCoder Beginner Contest 054

Submission #1588651

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 (nmap[make_tuple(ao, bo)] == 0 || 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 == 0 || 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状態 AC
Score得点 400
Source lengthソースコード長 1412 Byte
File nameファイル名
Exec time実行時間 99 ms
Memory usageメモリ使用量 2944 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt
All 400 / 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 AC 2 ms 384 KB
subtask_1_06.txt AC 7 ms 768 KB
subtask_1_07.txt AC 12 ms 1024 KB
subtask_1_08.txt AC 15 ms 1024 KB
subtask_1_09.txt AC 24 ms 1408 KB
subtask_1_10.txt AC 38 ms 1664 KB
subtask_1_11.txt AC 53 ms 2048 KB
subtask_1_12.txt AC 99 ms 2944 KB
subtask_1_13.txt AC 81 ms 2688 KB
subtask_1_14.txt AC 74 ms 2304 KB
subtask_1_15.txt AC 86 ms 2816 KB
subtask_1_16.txt AC 90 ms 2944 KB
subtask_1_17.txt AC 95 ms 2944 KB
subtask_1_18.txt AC 86 ms 2816 KB