結果
問題 | No.1 道のショートカット |
ユーザー |
|
提出日時 | 2019-01-16 13:48:31 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 40 ms / 5,000 ms |
コード長 | 2,321 bytes |
コンパイル時間 | 879 ms |
コンパイル使用メモリ | 106,624 KB |
実行使用メモリ | 19,968 KB |
最終ジャッジ日時 | 2024-07-20 16:38:27 |
合計ジャッジ時間 | 2,955 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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; } } }