結果

問題 No.17 2つの地点に泊まりたい
ユーザー mbanmban
提出日時 2017-03-07 21:26:25
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 3,468 bytes
コンパイル時間 1,037 ms
コンパイル使用メモリ 114,628 KB
実行使用メモリ 26,264 KB
最終ジャッジ日時 2024-04-23 02:17:58
合計ジャッジ時間 2,604 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
24,180 KB
testcase_01 AC 26 ms
21,812 KB
testcase_02 AC 27 ms
26,096 KB
testcase_03 AC 27 ms
23,984 KB
testcase_04 AC 26 ms
26,264 KB
testcase_05 AC 26 ms
23,800 KB
testcase_06 AC 27 ms
23,952 KB
testcase_07 AC 26 ms
23,796 KB
testcase_08 AC 29 ms
21,812 KB
testcase_09 AC 30 ms
26,008 KB
testcase_10 AC 29 ms
26,096 KB
testcase_11 AC 28 ms
22,200 KB
testcase_12 AC 27 ms
23,672 KB
testcase_13 AC 26 ms
24,080 KB
testcase_14 AC 26 ms
23,672 KB
testcase_15 AC 27 ms
25,964 KB
testcase_16 AC 26 ms
24,212 KB
testcase_17 AC 26 ms
23,984 KB
testcase_18 AC 27 ms
23,800 KB
testcase_19 AC 28 ms
23,924 KB
testcase_20 AC 26 ms
23,800 KB
testcase_21 AC 26 ms
26,132 KB
testcase_22 AC 27 ms
21,684 KB
testcase_23 AC 27 ms
23,796 KB
testcase_24 AC 28 ms
23,928 KB
testcase_25 AC 26 ms
25,992 KB
testcase_26 AC 28 ms
23,844 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.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);
    }
}

0