結果

問題 No.762 PDCAパス
ユーザー vis103vis103
提出日時 2018-12-14 15:52:07
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 3,123 bytes
コンパイル時間 1,696 ms
コンパイル使用メモリ 110,664 KB
実行使用メモリ 33,768 KB
最終ジャッジ日時 2023-10-25 10:08:34
合計ジャッジ時間 7,273 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
25,860 KB
testcase_01 AC 30 ms
25,840 KB
testcase_02 AC 29 ms
25,848 KB
testcase_03 AC 29 ms
25,840 KB
testcase_04 AC 28 ms
25,756 KB
testcase_05 AC 29 ms
25,756 KB
testcase_06 AC 29 ms
25,840 KB
testcase_07 AC 29 ms
25,840 KB
testcase_08 AC 30 ms
25,840 KB
testcase_09 AC 29 ms
25,860 KB
testcase_10 AC 29 ms
25,860 KB
testcase_11 AC 30 ms
25,860 KB
testcase_12 AC 29 ms
25,868 KB
testcase_13 AC 30 ms
25,840 KB
testcase_14 AC 29 ms
25,756 KB
testcase_15 AC 30 ms
25,860 KB
testcase_16 AC 29 ms
25,856 KB
testcase_17 AC 30 ms
25,848 KB
testcase_18 AC 30 ms
25,848 KB
testcase_19 AC 29 ms
25,848 KB
testcase_20 AC 30 ms
25,848 KB
testcase_21 AC 30 ms
25,856 KB
testcase_22 AC 166 ms
31,188 KB
testcase_23 AC 166 ms
31,188 KB
testcase_24 AC 170 ms
33,532 KB
testcase_25 AC 168 ms
33,532 KB
testcase_26 AC 193 ms
33,768 KB
testcase_27 AC 192 ms
33,768 KB
testcase_28 AC 180 ms
31,960 KB
testcase_29 AC 183 ms
31,956 KB
testcase_30 AC 179 ms
31,764 KB
testcase_31 AC 179 ms
31,764 KB
testcase_32 AC 180 ms
31,768 KB
testcase_33 AC 179 ms
31,568 KB
testcase_34 AC 180 ms
31,568 KB
testcase_35 AC 179 ms
31,568 KB
testcase_36 AC 177 ms
31,296 KB
testcase_37 AC 177 ms
31,296 KB
testcase_38 AC 178 ms
31,296 KB
testcase_39 AC 179 ms
31,296 KB
testcase_40 AC 178 ms
31,296 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.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(0, 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) == "P" && s.Substring(p.To, 1) == "D")
                {
                    pathCount[p.To]++;
                }
                else if (s.Substring(p.From, 1) == "D" && s.Substring(p.To, 1) == "C")
                {
                    DCindex.Add(paths.Count - 1);
                }
                else if (s.Substring(p.From, 1) == "C" && s.Substring(p.To, 1) == "A")
                {
                    pathCount[p.From]++;
                }

            }
            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) == "P" && s.Substring(p.To, 1) == "D")
                {
                    pathCount[p.To]++;
                }
                else if (s.Substring(p.From, 1) == "D" && s.Substring(p.To, 1) == "C")
                {
                    DCindex.Add(paths.Count - 1);
                }
                else if (s.Substring(p.From, 1) == "C" && s.Substring(p.To, 1) == "A")
                {
                    pathCount[p.From]++;
                }
            }
        }

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

        int mod = 1000000007;
        ulong sum = 0;

        for (int i = 0; i < DCindex.Count; i++)
        {
            Path pDC = paths[DCindex[i]];
            
            sum += (ulong)(pathCount[pDC.To] * pathCount[pDC.From]);
            sum %= (ulong)mod;
        }
        
        Console.WriteLine(sum);
    }
}

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

0