結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー くれちーくれちー
提出日時 2017-03-25 00:14:13
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,473 bytes
コンパイル時間 2,269 ms
コンパイル使用メモリ 105,140 KB
実行使用メモリ 25,904 KB
最終ジャッジ日時 2023-09-20 07:05:21
合計ジャッジ時間 8,060 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
23,820 KB
testcase_01 AC 64 ms
21,840 KB
testcase_02 AC 65 ms
21,920 KB
testcase_03 AC 64 ms
21,732 KB
testcase_04 AC 66 ms
23,960 KB
testcase_05 AC 1,604 ms
25,904 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;
using System.Linq;

class Program
{
    const int inf = 1145141919;

    static int gx, gy, n, f;
    static int[] cx, cy, c;
    
    static T Min<T>(T x, T y) where T : IComparable
    {
        return x.CompareTo(y) < 0 ? x : y;
    }

    static int Search(int x, int y, int sum, List<int> cs)
    {
        if (x == gx && y == gy) return sum;
        if (x > gx || y > gy) return inf;
        int min = inf;
        min = Min(min, Search(x + 1, y, sum + f, cs));
        min = Min(min, Search(x, y + 1, sum + f, cs));
        for (var i = 0; i < n; i++)
        {
            if (cs.Contains(i))
            {
                var cs2 = new List<int>(cs);
                cs2.Remove(i);
                min = Min(min, Search(x + cx[i], y + cy[i], sum + c[i], cs2));
            }
        }
        return min;
    }

    static void Main()
    {
        {
            var tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
            gx = tmp[0]; gy = tmp[1]; n = tmp[2]; f = tmp[3];
            cx = new int[n]; cy = new int[n]; c = new int[n];
        }
        for (var i = 0; i < n; i++)
        {
            var tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
            cx[i] = tmp[0]; cy[i] = tmp[1]; c[i] = tmp[2];
        }
        var cs = new List<int>(n);
        for (var i = 0; i < n; i++) cs.Add(i);
        var ans = Search(0, 0, 0, cs);
        Console.WriteLine(ans);
    }
}
0