結果
| 問題 |
No.762 PDCAパス
|
| コンテスト | |
| ユーザー |
vis103
|
| 提出日時 | 2018-12-14 15:01:12 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,768 bytes |
| コンパイル時間 | 1,179 ms |
| コンパイル使用メモリ | 114,216 KB |
| 実行使用メモリ | 39,848 KB |
| 最終ジャッジ日時 | 2024-09-25 05:03:40 |
| 合計ジャッジ時間 | 6,194 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 TLE * 1 -- * 18 |
コンパイルメッセージ
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;
using System.Text;
using System.Threading.Tasks;
class Program
{
static void Main()
{
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>();
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 (pDC.pCount < 0)
{
n = paths.FindAll(a => a.To == pDC.From).Count();
}
else
{
n = pDC.pCount;
}
if (pDC.aCount < 0)
{
m = paths.FindAll(a => a.From == pDC.To).Count();
}
else
{
m = pDC.aCount;
}
sum += (ulong)(((m % mod) * (n % mod)) % mod);
sum %= (ulong)mod;
}
Console.WriteLine(sum);
}
}
class Path
{
public int From { get; set; }
public int To { get; set; }
public int pCount = -1;
public int aCount = -1;
}
vis103