結果

問題 No.1 道のショートカット
ユーザー HimatsubushinHimatsubushin
提出日時 2019-01-16 13:48:31
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 69 ms / 5,000 ms
コード長 2,321 bytes
コンパイル時間 4,210 ms
コンパイル使用メモリ 109,748 KB
実行使用メモリ 25,876 KB
最終ジャッジ日時 2023-09-27 22:18:07
合計ジャッジ時間 7,827 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
23,724 KB
testcase_01 AC 54 ms
23,780 KB
testcase_02 AC 54 ms
21,612 KB
testcase_03 AC 52 ms
21,676 KB
testcase_04 AC 52 ms
21,608 KB
testcase_05 AC 52 ms
21,852 KB
testcase_06 AC 53 ms
19,712 KB
testcase_07 AC 52 ms
21,756 KB
testcase_08 AC 65 ms
21,896 KB
testcase_09 AC 60 ms
23,896 KB
testcase_10 AC 62 ms
23,880 KB
testcase_11 AC 63 ms
21,848 KB
testcase_12 AC 65 ms
22,004 KB
testcase_13 AC 68 ms
21,984 KB
testcase_14 AC 52 ms
19,800 KB
testcase_15 AC 53 ms
23,652 KB
testcase_16 AC 59 ms
21,716 KB
testcase_17 AC 52 ms
21,676 KB
testcase_18 AC 52 ms
23,884 KB
testcase_19 AC 54 ms
21,784 KB
testcase_20 AC 61 ms
21,872 KB
testcase_21 AC 59 ms
21,868 KB
testcase_22 AC 53 ms
21,736 KB
testcase_23 AC 69 ms
21,796 KB
testcase_24 AC 61 ms
25,876 KB
testcase_25 AC 59 ms
21,872 KB
testcase_26 AC 62 ms
23,820 KB
testcase_27 AC 64 ms
23,956 KB
testcase_28 AC 54 ms
21,608 KB
testcase_29 AC 64 ms
21,832 KB
testcase_30 AC 59 ms
21,884 KB
testcase_31 AC 63 ms
21,884 KB
testcase_32 AC 65 ms
21,832 KB
testcase_33 AC 65 ms
21,844 KB
testcase_34 AC 63 ms
21,860 KB
testcase_35 AC 60 ms
23,884 KB
testcase_36 AC 60 ms
21,852 KB
testcase_37 AC 62 ms
23,888 KB
testcase_38 AC 53 ms
21,720 KB
testcase_39 AC 59 ms
21,828 KB
testcase_40 AC 59 ms
21,936 KB
testcase_41 AC 60 ms
21,788 KB
testcase_42 AC 53 ms
23,780 KB
testcase_43 AC 52 ms
21,608 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.Linq;

namespace No001_道のショートカット
{
    class Program
    {
        static int n;
        static int c;
        static int v;
        static int m_mon;
        static int m_tim;

        static int[] s;
        static int[] t;
        static int[] y;
        static int[] m;

        static void Main(string[] args)
        {
            n = int.Parse(Console.ReadLine());
            c = int.Parse(Console.ReadLine());
            v = int.Parse(Console.ReadLine());

            string[] in_s = Console.ReadLine().Split(' ');
            s = in_s.Select(int.Parse).ToArray();
            string[] in_t = Console.ReadLine().Split(' ');
            t = in_t.Select(int.Parse).ToArray();
            string[] in_y = Console.ReadLine().Split(' ');
            y = in_y.Select(int.Parse).ToArray();
            string[] in_m = Console.ReadLine().Split(' ');
            m = in_m.Select(int.Parse).ToArray();

            Sort();

            m_mon = 0;
            m_tim = 0;

            Check(1, 0, 0);

            if (m_tim == 0)
                Console.WriteLine(-1);
            else
                Console.WriteLine(m_tim);
        }

        static void Sort()
        {
            for (int i = 0; i < v - 1; i++)
                for (int j = i; j < v; j++)
                    if (s[i] > s[j])
                        Swap(i, j);
        }

        static void Swap(int a, int b)
        {
            int temp = s[a];
            s[a] = s[b];
            s[b] = temp;

            temp = t[a];
            t[a] = t[b];
            t[b] = temp;

            temp = y[a];
            y[a] = y[b];
            y[b] = temp;

            temp = m[a];
            m[a] = m[b];
            m[b] = temp;
        }

        static void Check(int level, int money, int time)
        {
            if (money > c)
                return;

            if (time > m_tim && m_tim != 0)
                return;

            if (level == n)
            {
                m_mon = money;
                m_tim = time;
            }
            else
                for (int i = 0; i < v; i++)
                    if (s[i] == level)
                        Check(t[i], money + y[i], time + m[i]);
                    else if (s[i] > level)
                        break;
        }
    }
}
0