結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー kuuso1kuuso1
提出日時 2017-03-24 22:57:28
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,952 bytes
コンパイル時間 2,667 ms
コンパイル使用メモリ 105,436 KB
実行使用メモリ 22,872 KB
最終ジャッジ日時 2023-09-20 02:32:07
合計ジャッジ時間 5,520 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
20,800 KB
testcase_01 AC 58 ms
20,856 KB
testcase_02 AC 58 ms
22,872 KB
testcase_03 AC 57 ms
22,772 KB
testcase_04 AC 57 ms
20,816 KB
testcase_05 AC 57 ms
22,848 KB
testcase_06 AC 57 ms
20,868 KB
testcase_07 AC 56 ms
20,856 KB
testcase_08 AC 58 ms
20,840 KB
testcase_09 AC 58 ms
20,920 KB
testcase_10 AC 57 ms
20,876 KB
testcase_11 AC 57 ms
20,836 KB
testcase_12 AC 57 ms
20,832 KB
testcase_13 AC 57 ms
20,732 KB
testcase_14 AC 57 ms
22,792 KB
testcase_15 AC 57 ms
18,780 KB
testcase_16 AC 58 ms
20,804 KB
testcase_17 AC 56 ms
20,820 KB
testcase_18 AC 58 ms
20,928 KB
testcase_19 AC 57 ms
20,828 KB
testcase_20 AC 57 ms
20,844 KB
testcase_21 AC 58 ms
22,872 KB
testcase_22 AC 57 ms
18,876 KB
testcase_23 AC 59 ms
20,860 KB
testcase_24 AC 59 ms
20,796 KB
testcase_25 AC 59 ms
22,788 KB
testcase_26 AC 59 ms
20,872 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int H = Gy+1;
		int W = Gx+1;
		int[][] dp = new int[H][];
		int Inf = (int)1e9;
		for(int i=0;i<H;i++){
			dp[i] = new int[W];
			for(int j=0;j<W;j++){
				dp[i][j] = Inf;
			}
		}
		
		dp[0][0] = 0;
		for(int k=0;k<N;k++){
			for(int i=H-1;i>=0;i--){
				for(int j=W-1;j>=0;j--){
					if(dp[i][j] == Inf) continue;
					int ny = i + Y[k];
					int nx = j + X[k];
					int nc = dp[i][j] + C[k];
					if(InRange(ny,0,H) && InRange(nx,0,W)){
						dp[ny][nx] = Math.Min(dp[ny][nx],nc);
					}
				}
			}
//for(int i=0;i<H;i++)Console.WriteLine(String.Join(" ",dp[i]));Console.WriteLine();
		}
		
		int min = Inf;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				int rest = Gx - j + Gy - i;
				min = Math.Min(rest*F + dp[i][j], min);
			}
		}
		
		Console.WriteLine(min);
		
	}
	
	bool InRange(int t, int l, int r){
		return l <= t && t < r;
	}
	
	int Gx,Gy,N,F;
	int[] X,Y,C;
	public Sol(){
		var d = ria();
		Gx = d[0]; Gy = d[1]; N = d[2]; F = d[3];
		X = new int[N];
		Y = new int[N];
		C = new int[N];
		for(int i=0;i<N;i++){
			d = ria();
			X[i] = d[0]; Y[i] = d[1]; C[i] = d[2];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0