結果
| 問題 |
No.95 Alice and Graph
|
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2014-12-21 23:30:54 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,324 bytes |
| コンパイル時間 | 1,564 ms |
| コンパイル使用メモリ | 107,136 KB |
| 実行使用メモリ | 27,648 KB |
| 最終ジャッジ日時 | 2024-06-12 03:18:17 |
| 合計ジャッジ時間 | 7,031 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 8 |
コンパイルメッセージ
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.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);
}
}
}
nanophoto12