結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー startcppstartcpp
提出日時 2017-03-24 22:53:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 59,112 KB
実行使用メモリ 5,780 KB
最終ジャッジ日時 2023-09-20 01:59:15
合計ジャッジ時間 1,599 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int gx, gy, n, f;
int X[52], Y[52], c[52];
int dp[53][101][101];	//dp[id][x][y]

int main() {
	int i, x, y, j;
	
	cin >> gx >> gy >> n >> f;
	rep(i, n) cin >> X[i] >> Y[i] >> c[i];
	X[n] = 1; Y[n] = 0; c[n] = f;
	X[n + 1] = 0; Y[n + 1] = 1; c[n + 1] = f;
	n += 2;
	
	rep(i, n + 1) rep(x, gx + 1) rep(y, gy + 1) dp[i][x][y] = 11451419;
	
	//同じクリスタルは1回しか使えない, とした場合.
	dp[0][0][0] = 0;
	rep(i, n) {
		rep(x, gx + 1) {
			rep(y, gy + 1) {
				//地点(x, y)でクリスタルiをj回使う
				for (j = 0; j < (i < n - 2 ? 2 : 114514); j++) {
					int nx = x + X[i] * j;
					int ny = y + Y[i] * j;
					if (nx > gx || ny > gy) break;
					dp[i + 1][nx][ny] = min(dp[i + 1][nx][ny], dp[i][x][y] + c[i] * j);
				}
			}
		}
	}
	
	cout << dp[n][gx][gy] << endl;
	return 0;
}
0