結果

問題 No.488 四角関係
ユーザー 14番14番
提出日時 2017-05-31 08:04:50
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 112 ms / 5,000 ms
コード長 3,649 bytes
コンパイル時間 2,899 ms
コンパイル使用メモリ 114,916 KB
実行使用メモリ 30,388 KB
最終ジャッジ日時 2023-10-21 18:59:47
合計ジャッジ時間 3,951 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
26,100 KB
testcase_01 AC 72 ms
30,288 KB
testcase_02 AC 59 ms
28,148 KB
testcase_03 AC 55 ms
28,148 KB
testcase_04 AC 57 ms
28,148 KB
testcase_05 AC 73 ms
30,276 KB
testcase_06 AC 52 ms
26,100 KB
testcase_07 AC 112 ms
30,388 KB
testcase_08 AC 41 ms
25,768 KB
testcase_09 AC 36 ms
25,768 KB
testcase_10 AC 53 ms
26,100 KB
testcase_11 AC 49 ms
26,100 KB
testcase_12 AC 52 ms
26,104 KB
testcase_13 AC 56 ms
26,100 KB
testcase_14 AC 51 ms
26,104 KB
testcase_15 AC 38 ms
25,776 KB
testcase_16 AC 50 ms
26,092 KB
testcase_17 AC 35 ms
25,764 KB
testcase_18 AC 48 ms
26,096 KB
testcase_19 AC 51 ms
26,096 KB
testcase_20 AC 50 ms
26,092 KB
testcase_21 AC 39 ms
25,776 KB
testcase_22 AC 41 ms
25,856 KB
testcase_23 AC 40 ms
25,776 KB
testcase_24 AC 52 ms
26,104 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.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();
	}
}
0