結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー kurenai3110
提出日時 2017-03-24 22:42:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 869 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 77,132 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 22:06:52
合計ジャッジ時間 1,962 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int DP[51][51];

int main()
{
	int Gx, Gy, N, F;cin >> Gx >> Gy >> N >> F;
	
	vector<int>x(N), y(N), c(N);
	for (int i = 0;i < N;i++) {
		cin >> x[i] >> y[i] >> c[i];
	}

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

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

	cout << ans << endl;

    return 0;
}

0