結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー kurenai3110kurenai3110
提出日時 2017-03-25 00:15:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,080 bytes
コンパイル時間 1,259 ms
コンパイル使用メモリ 79,896 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-20 07:12:46
合計ジャッジ時間 2,539 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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 {
		if (x + y != right.x + right.y)return x + y > right.x + right.y;
		return x > right.x;
	}
};

int main()
{
	int Gx, Gy, N, F;cin >> Gx >> Gy >> N >> F;
	
	vector<pair<int,POS>>xyc(N);
	for (int i = 0;i < N;i++) {
		cin >> xyc[i].second.x >> xyc[i].second.y >> 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.x;pos.y += xyc[i].second.y;
			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