結果

問題 No.762 PDCAパス
ユーザー vis103vis103
提出日時 2018-12-14 15:25:46
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,995 bytes
コンパイル時間 1,119 ms
コンパイル使用メモリ 112,160 KB
実行使用メモリ 38,068 KB
最終ジャッジ日時 2023-10-25 10:05:01
合計ジャッジ時間 6,554 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
30,308 KB
testcase_01 AC 30 ms
25,924 KB
testcase_02 AC 30 ms
25,924 KB
testcase_03 AC 30 ms
25,924 KB
testcase_04 AC 29 ms
25,792 KB
testcase_05 AC 29 ms
25,792 KB
testcase_06 AC 30 ms
25,924 KB
testcase_07 AC 30 ms
25,924 KB
testcase_08 AC 30 ms
25,924 KB
testcase_09 AC 30 ms
25,936 KB
testcase_10 AC 31 ms
25,936 KB
testcase_11 AC 30 ms
25,936 KB
testcase_12 AC 30 ms
25,936 KB
testcase_13 AC 29 ms
25,932 KB
testcase_14 AC 29 ms
25,792 KB
testcase_15 AC 30 ms
25,936 KB
testcase_16 AC 30 ms
25,924 KB
testcase_17 AC 30 ms
25,924 KB
testcase_18 AC 30 ms
25,924 KB
testcase_19 AC 31 ms
25,924 KB
testcase_20 AC 30 ms
25,924 KB
testcase_21 AC 30 ms
25,924 KB
testcase_22 AC 200 ms
31,280 KB
testcase_23 AC 201 ms
31,280 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static int[] pathCount;

    static void Main()
    {
        Console.SetIn(new System.IO.StreamReader(Console.OpenStandardInput((int)Math.Pow(10,5))));
        string[] arr = Console.ReadLine().Split(' ');
        int N = int.Parse(arr[0]);
        int M = int.Parse(arr[1]);
        string s = Console.ReadLine();
        List<Path> paths = new List<Path>();
        List<int> DCindex = new List<int>();

        pathCount = Enumerable.Repeat(-1, N).ToArray();

        for (int i = 0; i < M; i++)
        {
            arr = Console.ReadLine().Split(' ');
            Path p = new Path();

            p.From = int.Parse(arr[0]) - 1;
            p.To = int.Parse(arr[1]) - 1;

            if(s.Substring(p.From, 1) == "P" && s.Substring(p.To, 1) == "D" ||
               s.Substring(p.From, 1) == "D" && s.Substring(p.To, 1) == "C" ||
               s.Substring(p.From, 1) == "C" && s.Substring(p.To, 1) == "A")
            {
                p.From = int.Parse(arr[0]) - 1;
                p.To = int.Parse(arr[1]) - 1;
                paths.Add(p);
                if(s.Substring(p.From, 1) == "D" && s.Substring(p.To, 1) == "C")
                {
                    DCindex.Add(paths.Count - 1);
                }
            }
            else if(s.Substring(p.To, 1) == "P" && s.Substring(p.From, 1) == "D" ||
                    s.Substring(p.To, 1) == "D" && s.Substring(p.From, 1) == "C" ||
                    s.Substring(p.To, 1) == "C" && s.Substring(p.From, 1) == "A")
            {
                p.To = int.Parse(arr[0]) - 1;
                p.From = int.Parse(arr[1]) - 1;
                paths.Add(p);
                if (s.Substring(p.From, 1) == "D" && s.Substring(p.To, 1) == "C")
                {
                    DCindex.Add(paths.Count - 1);
                }
            }
        }

        if(DCindex.Count == 0)
        {
            Console.WriteLine("0");
            return;
        }

        int mod = 1000000007;
        ulong sum = 0;

        for (int i = 0; i < DCindex.Count; i++)
        {
            long n = 0;
            long m = 0;

            Path pDC = paths[DCindex[i]];

            if (pathCount[pDC.From] < 0)
            {
                n = paths.FindAll(a => a.To == pDC.From).Count();
                pathCount[pDC.From] = (int)n;
            }
            else
            {
                n = pathCount[pDC.From];
            }

            if (pathCount[pDC.To] < 0)
            {
                m = paths.FindAll(a => a.From == pDC.To).Count();
                pathCount[pDC.To] = (int)m;
            }
            else
            {
                m = pathCount[pDC.To];
            }

            sum += (ulong)(m * n);
            sum %= (ulong)mod;
        }


        Console.WriteLine(sum);
    }
}

class Path
{
    public int From { get; set; }
    public int To { get; set; }
}

0