結果

問題 No.17 2つの地点に泊まりたい
ユーザー mbanmban
提出日時 2017-03-07 21:26:25
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 3,468 bytes
コンパイル時間 2,652 ms
コンパイル使用メモリ 107,772 KB
実行使用メモリ 22,824 KB
最終ジャッジ日時 2023-08-05 03:50:36
合計ジャッジ時間 5,139 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
20,784 KB
testcase_01 AC 58 ms
22,728 KB
testcase_02 AC 58 ms
20,660 KB
testcase_03 AC 58 ms
20,732 KB
testcase_04 AC 58 ms
20,692 KB
testcase_05 AC 61 ms
22,704 KB
testcase_06 AC 60 ms
20,680 KB
testcase_07 AC 60 ms
20,692 KB
testcase_08 AC 61 ms
20,688 KB
testcase_09 AC 61 ms
20,736 KB
testcase_10 AC 60 ms
20,780 KB
testcase_11 AC 61 ms
20,680 KB
testcase_12 AC 57 ms
20,684 KB
testcase_13 AC 57 ms
20,632 KB
testcase_14 AC 57 ms
20,728 KB
testcase_15 AC 56 ms
20,780 KB
testcase_16 AC 57 ms
22,736 KB
testcase_17 AC 57 ms
20,776 KB
testcase_18 AC 60 ms
22,732 KB
testcase_19 AC 58 ms
18,788 KB
testcase_20 AC 58 ms
20,724 KB
testcase_21 AC 57 ms
20,800 KB
testcase_22 AC 57 ms
18,692 KB
testcase_23 AC 59 ms
20,732 KB
testcase_24 AC 59 ms
22,824 KB
testcase_25 AC 57 ms
20,816 KB
testcase_26 AC 59 ms
22,772 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