結果
| 問題 |
No.488 四角関係
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2017-05-31 08:04:50 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 110 ms / 5,000 ms |
| コード長 | 3,649 bytes |
| コンパイル時間 | 1,353 ms |
| コンパイル使用メモリ | 110,464 KB |
| 実行使用メモリ | 24,064 KB |
| 最終ジャッジ日時 | 2024-09-21 20:16:50 |
| 合計ジャッジ時間 | 3,443 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public void Proc() {
int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
int nodeCount = inpt[0];
int pathCount = inpt[1];
for (int i = 0; i < pathCount; i++) {
inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
int[][] tmp = new int[][] { inpt, inpt.Reverse().ToArray() };
foreach(int[] lst in tmp) {
if(!Path.ContainsKey(lst[0])) {
Path.Add(lst[0],new Dictionary<int, bool>());
}
Path[lst[0]].Add(lst[1], true);
}
}
Dictionary<int, Dictionary<int, Dictionary<int, Dictionary<int, bool>>>> dic = new Dictionary<int, Dictionary<int, Dictionary<int, Dictionary<int, bool>>>>();
foreach(int key1 in Path.Keys) {
if(Path[key1].Count < 2) {
continue;
}
int[] key1ToList = Path[key1].Keys.ToArray();
for (int i = 0; i < key1ToList.Length - 1;i++) {
for (int j = i + 1; j < key1ToList.Length;j++) {
if(Path[key1ToList[i]].ContainsKey(key1ToList[j])) {
continue;
}
if(!Path.Any(a=>a.Key != key1 && a.Value.ContainsKey(key1ToList[i]) && a.Value.ContainsKey(key1ToList[j]))) {
continue;
}
int[] key2List = Path.Where(a => a.Key != key1 && a.Value.ContainsKey(key1ToList[i]) && a.Value.ContainsKey(key1ToList[j])).Select(a => a.Key).ToArray();
foreach(int key2 in key2List) {
if(Path[key2].ContainsKey(key1)) {
continue;
}
int[] tmp = new int[]{key1, key2, key1ToList[i], key1ToList[j]}.OrderBy(a=>a).ToArray();
if(!dic.ContainsKey(tmp[0])) {
dic.Add(tmp[0], new Dictionary<int, Dictionary<int, Dictionary<int, bool>>>());
}
if(!dic[tmp[0]].ContainsKey(tmp[1])) {
dic[tmp[0]].Add(tmp[1], new Dictionary<int, Dictionary<int, bool>>());
}
if(!dic[tmp[0]][tmp[1]].ContainsKey(tmp[2])) {
dic[tmp[0]][tmp[1]].Add(tmp[2], new Dictionary<int, bool>());
}
dic[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = true;
}
}
}
}
int ans = dic.Select(a => a.Value.Select(b => b.Value.Select(c => c.Value.Count()).Sum()).Sum()).Sum();
Console.WriteLine(ans);
}
private Dictionary<int, Dictionary<int, bool>> Path = new Dictionary<int, Dictionary<int, bool>>();
public class Reader
{
private static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine() {
if(IsDebug) {
if(sr == null) {
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
private static string InputText = @"
8 17
0 3
0 4
0 6
1 2
1 6
2 4
2 5
2 7
3 4
3 5
3 6
4 5
4 6
4 7
5 6
5 7
6 7
";
}
public static void Main(string[] args)
{
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
14番