結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2017-03-24 22:48:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,701 bytes
コンパイル時間 1,192 ms
コンパイル使用メモリ 144,524 KB
実行使用メモリ 8,876 KB
最終ジャッジ日時 2023-09-20 01:53:33
合計ジャッジ時間 2,239 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,604 KB
testcase_01 AC 4 ms
8,536 KB
testcase_02 AC 5 ms
8,596 KB
testcase_03 AC 5 ms
8,616 KB
testcase_04 AC 5 ms
8,604 KB
testcase_05 AC 5 ms
8,608 KB
testcase_06 AC 5 ms
8,552 KB
testcase_07 AC 4 ms
8,600 KB
testcase_08 AC 5 ms
8,536 KB
testcase_09 AC 5 ms
8,536 KB
testcase_10 AC 5 ms
8,560 KB
testcase_11 AC 5 ms
8,740 KB
testcase_12 AC 6 ms
8,748 KB
testcase_13 AC 5 ms
8,556 KB
testcase_14 AC 5 ms
8,876 KB
testcase_15 AC 5 ms
8,536 KB
testcase_16 AC 5 ms
8,616 KB
testcase_17 AC 5 ms
8,876 KB
testcase_18 AC 5 ms
8,680 KB
testcase_19 AC 5 ms
8,548 KB
testcase_20 AC 5 ms
8,592 KB
testcase_21 AC 5 ms
8,600 KB
testcase_22 AC 5 ms
8,680 KB
testcase_23 AC 6 ms
8,540 KB
testcase_24 AC 5 ms
8,564 KB
testcase_25 AC 6 ms
8,556 KB
testcase_26 AC 5 ms
8,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;
#define int long long
int Gx, Gy, N, F;
int x[55], y[55], c[55];
int dp[55][110][110];

signed main(void){
	cin >> Gx >> Gy >> N >> F;
	rep(i, N) cin >> x[i] >> y[i] >> c[i];
	/*
	vector<pair<double, int>> v;
	rep(i, N){
		int dist = x[i] + y[i];
		double cost = (double)c[i] / (double)dist;
		if(cost < F) v.pb(mp(cost, i));
	}
	sort(all(v));
	*/
	rep(i, 55)rep(j, 110)rep(k, 110) dp[i][j][k] = INF;
	dp[0][0][0] = 0;
	rep(i, N)rep(j, 101)rep(k, 101){
		if(dp[i][j][k] == INF) continue;
		chmin(dp[i + 1][j][k], dp[i][j][k]);
		if(j + x[i] <= 101 && k + y[i] <= 101)
			chmin(dp[i + 1][j + x[i]][k + y[i]], dp[i][j][k] + c[i]);
	}

	/*
	int sx = 0, sy = 0;
	int ret = 0;
	for(auto u : v){
		int i = u.se;
		if(sx + x[i] <= Gx && sy + y[i] <= Gy){
			sx += x[i]; sy += y[i];
			ret += c[i];
		}
	}
	int k = (Gx - sx) + (Gy - sy);
	*/
	int ans = INF;
	rep(i, Gx + 1)rep(j, Gy + 1){
		if(dp[N][i][j] == INF) continue;
		int dist = (Gx - i) + (Gy - j);
		chmin(ans, dp[N][i][j] + dist * F);
	}
	cout << ans << endl;
	return 0;
}
0