結果
問題 | No.17 2つの地点に泊まりたい |
ユーザー | mban |
提出日時 | 2017-03-07 21:26:25 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 25 ms / 5,000 ms |
コード長 | 3,468 bytes |
コンパイル時間 | 2,064 ms |
コンパイル使用メモリ | 108,544 KB |
実行使用メモリ | 17,920 KB |
最終ジャッジ日時 | 2024-10-15 01:39:38 |
合計ジャッジ時間 | 3,409 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
17,792 KB |
testcase_01 | AC | 22 ms
17,664 KB |
testcase_02 | AC | 24 ms
17,664 KB |
testcase_03 | AC | 24 ms
17,664 KB |
testcase_04 | AC | 21 ms
17,664 KB |
testcase_05 | AC | 23 ms
17,920 KB |
testcase_06 | AC | 22 ms
17,792 KB |
testcase_07 | AC | 22 ms
17,920 KB |
testcase_08 | AC | 25 ms
17,920 KB |
testcase_09 | AC | 23 ms
17,920 KB |
testcase_10 | AC | 22 ms
17,792 KB |
testcase_11 | AC | 23 ms
17,920 KB |
testcase_12 | AC | 22 ms
17,536 KB |
testcase_13 | AC | 22 ms
17,920 KB |
testcase_14 | AC | 21 ms
17,536 KB |
testcase_15 | AC | 22 ms
17,664 KB |
testcase_16 | AC | 21 ms
17,408 KB |
testcase_17 | AC | 21 ms
17,792 KB |
testcase_18 | AC | 23 ms
17,792 KB |
testcase_19 | AC | 22 ms
17,536 KB |
testcase_20 | AC | 21 ms
17,664 KB |
testcase_21 | AC | 22 ms
17,664 KB |
testcase_22 | AC | 24 ms
17,792 KB |
testcase_23 | AC | 22 ms
17,920 KB |
testcase_24 | AC | 23 ms
17,664 KB |
testcase_25 | AC | 21 ms
17,664 KB |
testcase_26 | AC | 23 ms
17,792 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; using System.ComponentModel; class Program { static void Main(string[] args) { new Magatro().Solve(); } } public class Scanner { private StreamReader Sr; private string[] S; private int Index; private const char Separator = ' '; public Scanner() : this(Console.OpenStandardInput()) { Index = 0; S = new string[0]; } public Scanner(Stream source) { Sr = new StreamReader(source); } private string[] Line() { return Sr.ReadLine().Split(Separator); } public string Next() { string result; if (Index >= S.Length) { S = Line(); Index = 0; } result = S[Index]; Index++; return result; } public T Next<T>() { var converter = TypeDescriptor.GetConverter(typeof(T)); return (T)converter.ConvertFromString(Next()); } public int NextInt() { return int.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public decimal NextDecimal() { return decimal.Parse(Next()); } public string[] StringArray(int index = 0) { Next(); Index = S.Length; return S.Skip(index).ToArray(); } public int[] IntArray(int index = 0) { return StringArray(index).Select(int.Parse).ToArray(); } public long[] LongArray(int index = 0) { return StringArray(index).Select(long.Parse).ToArray(); } public bool EndOfStream { get { return Sr.EndOfStream; } } } public class Magatro { private int[,] Dist; private int N; private int[] S; private int M; private const int Infinity = 999999; private void Scan() { Scanner cin = new Scanner(); N = cin.NextInt(); S = new int[N]; for (int i = 0; i < N; i++) { S[i] = cin.NextInt(); } M = cin.NextInt(); Dist = new int[N, N]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { Dist[i, j] = Infinity; } } for (int i = 0; i < M; i++) { int a = cin.NextInt(); int b = cin.NextInt(); int c = cin.NextInt(); Dist[a, b] = c; Dist[b, a] = c; } } public void Solve() { Scan(); for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { Dist[i, j] = Math.Min(Dist[i, j], Dist[i, k] + Dist[k, j]); } } } int anser = int.MaxValue; for (int a = 1; a < N - 1; a++) { for (int b = 1; b < N - 1; b++) { if (a == b) continue; int distCost = Dist[0, a] + Dist[a, b] + Dist[b, N - 1]; int stayCost = S[a] + S[b]; anser = Math.Min(distCost + stayCost, anser); } } Console.WriteLine(anser); } }