結果

問題 No.95 Alice and Graph
ユーザー nanophoto12nanophoto12
提出日時 2014-12-22 01:42:37
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,616 bytes
コンパイル時間 4,637 ms
コンパイル使用メモリ 103,752 KB
実行使用メモリ 32,020 KB
最終ジャッジ日時 2023-09-02 21:23:55
合計ジャッジ時間 25,014 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,977 ms
29,984 KB
testcase_01 AC 411 ms
28,000 KB
testcase_02 AC 406 ms
30,148 KB
testcase_03 AC 556 ms
30,016 KB
testcase_04 AC 2,971 ms
29,988 KB
testcase_05 AC 2,332 ms
30,104 KB
testcase_06 AC 2,920 ms
29,980 KB
testcase_07 AC 409 ms
29,968 KB
testcase_08 AC 64 ms
23,336 KB
testcase_09 AC 62 ms
21,876 KB
testcase_10 AC 62 ms
21,928 KB
testcase_11 AC 66 ms
25,348 KB
testcase_12 AC 65 ms
21,908 KB
testcase_13 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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)
        {
            var firstLine = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var n = firstLine[0];
            var m = firstLine[1];
            var k = firstLine[2];

            int[,] graph = new int[n, n];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    graph[i, j] = 1000;
                }                
            }
            for (int i = 0; i < n; i++)
            {
                graph[i, i] = 0;                
            }

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

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    for (int l = 0; l < n; l++)
                    {
                        graph[l, j] = Math.Min(graph[l, j], graph[l, i] + graph[i, 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] = 0x3f;
                    }
                }
                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))
                                {
                                    //移動回数をメモする
                                    var element = dp[mask ^ (1 << x), y] + graph[vertexs[x], vertexs[y]];
                                    if (element < dp[mask, x])
                                    {
                                        dp[mask, x] = element;
                                    }
                                }
                            }
                        }
                    }
                }
                bool canMove = false;
                int count1 = vertexs.Count;
                for (int j = 0; j < count1; j++)
                {
                    if (dp[(1 << count1) - 1, j] <= k)
                    {
                        canMove = true;
                    }
                }
                if (!canMove)
                {
                    vertexs.Remove(i);
                }
                else
                {
                    score += (1L << i) - 1L;
                }
            }
            Console.WriteLine(score);
        }
    }
}
0