結果

問題 No.95 Alice and Graph
ユーザー nanophoto12nanophoto12
提出日時 2014-12-21 23:30:54
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,324 bytes
コンパイル時間 3,279 ms
コンパイル使用メモリ 105,168 KB
実行使用メモリ 34,204 KB
最終ジャッジ日時 2023-09-02 20:59:24
合計ジャッジ時間 9,393 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 491 ms
29,992 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 62 ms
21,720 KB
testcase_09 AC 61 ms
21,788 KB
testcase_10 AC 62 ms
21,944 KB
testcase_11 AC 65 ms
21,780 KB
testcase_12 AC 65 ms
23,932 KB
testcase_13 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;
using System.Linq;

namespace Yukicoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] graph = new int[64,64];

            var firstLine = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var n = firstLine[0];
            var m = firstLine[1];
            var k = firstLine[2];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    graph[i, j] = int.MaxValue/3;
                }                
            }

            for (int i = 0; i < m; i++)
            {
                var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                graph[line[0], line[1]] = 1;
                graph[line[1], line[0]] = 1;
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    for (int l = 0; l < n; l++)
                    {
                        graph[i, j] = Math.Min(graph[i, j], graph[i, k] + graph[k, j]);
                    }
                }
            }

            List<int> vertexs = new List<int>();
            vertexs.Add(0);
            long score = 0L;
            int[,] dp = new int[1 << 17, 17];
            for (int i = n - 1; i > 0; i--)
            {
                if (vertexs.Count >= k + 1)
                {
                    break;
                }
                vertexs.Add(i);
                for (int j = 0; j < 1 << 17; j++)
                {
                    for (int l = 0; l < 17; l++)
                    {
                        dp[j, l] = int.MaxValue/2;
                    }
                }
                dp[1, 0] = 0;
                int count = vertexs.Count;
                for (int mask = 1; mask < 1 << count; mask++)
                {
                    for (int x = 0; x < count; x++)
                    {
                        if ((mask & (1 << x)) == (1<<x))
                        {
                            for (int y = 0; y < count; y++)
                            {
                                if (x == y)
                                {
                                    continue;
                                }
                                if ((mask & (1 << y)) == (1 << y))
                                {
                                    //移動回数をメモする
                                    dp[mask, x] = Math.Min(dp[mask, x],
                                       dp[mask ^ (1 << x), y] + graph[vertexs[x], vertexs[y]]);
                                }
                            }
                        }
                    }
                }
                bool canMove = false;
                for (int j = 0; j < count; j++)
                {
                    if (dp[1 << count - 1, j] <= k)
                    {
                        canMove = true;
                    }
                }
                if (!canMove)
                {
                    vertexs.Remove(i);
                }
                else
                {
                    score += (1L << i) - 1L;
                }
            }
            Console.WriteLine(score);
        }
    }
}
0