結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー kurenai3110kurenai3110
提出日時 2017-03-24 23:07:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,057 bytes
コンパイル時間 2,504 ms
コンパイル使用メモリ 80,036 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-20 03:05:06
合計ジャッジ時間 3,518 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 WA -
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,376 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

struct POS {
	int x, y;

	bool operator<(const POS &right)const {
		return x + y > right.x + right.y;
	}
};

int main()
{
	int Gx, Gy, N, F;cin >> Gx >> Gy >> N >> F;
	
	vector<pair<int, pair<int, int>>>xyc(N);
	for (int i = 0;i < N;i++) {
		cin >> xyc[i].second.first >> xyc[i].second.second >> xyc[i].first;
	}
	sort(xyc.begin(), xyc.end());

	map<POS, int>M;
	POS p = { 0,0 };
	M[p] = 0;
	for (int i = 0;i < N;i++) {
		for (auto itr = M.begin();itr != M.end();itr++) {
			POS pos = itr->first;
			pos.x += xyc[i].second.first;pos.y += xyc[i].second.second;
			if (pos.x > Gx || pos.y > Gy)continue;
			if (M.find(pos) == M.end()) {
				M[pos] = itr->second + xyc[i].first;
			}
			else M[pos] = min(M[pos], itr->second + xyc[i].first);
		}
	}

	int ans = 1e8;
	for (auto itr = M.begin();itr != M.end();itr++) {
		ans = min(ans, itr->second + F*abs(itr->first.x - Gx) + F*abs(itr->first.y - Gy));
	}

	cout << ans << endl;

    return 0;
}

0