結果

問題 No.762 PDCAパス
ユーザー iicafiaxusiicafiaxus
提出日時 2018-12-10 12:46:48
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 1,534 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 117,868 KB
実行使用メモリ 23,956 KB
最終ジャッジ日時 2023-09-03 21:31:13
合計ジャッジ時間 5,242 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 101 ms
12,884 KB
testcase_23 AC 102 ms
12,032 KB
testcase_24 AC 122 ms
21,884 KB
testcase_25 AC 120 ms
23,492 KB
testcase_26 AC 94 ms
12,412 KB
testcase_27 AC 95 ms
12,348 KB
testcase_28 AC 190 ms
23,956 KB
testcase_29 AC 188 ms
22,800 KB
testcase_30 AC 183 ms
22,804 KB
testcase_31 AC 183 ms
22,596 KB
testcase_32 AC 176 ms
22,564 KB
testcase_33 AC 166 ms
22,584 KB
testcase_34 AC 172 ms
22,556 KB
testcase_35 AC 168 ms
22,612 KB
testcase_36 AC 135 ms
15,760 KB
testcase_37 AC 139 ms
15,760 KB
testcase_38 AC 131 ms
20,128 KB
testcase_39 AC 135 ms
20,612 KB
testcase_40 AC 135 ms
20,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

const long MOD = 1000000007;

class Node{
 int id;
 char value;
 bool hasMemo;
 long memo;
 Node[] nodes;
 this(int id){
  this.id = id;
 }
 override string toString(){
  return this.id.to!string ~ " " ~ this.value;
 }
}


void main(){
 int n = read.to!int;
 Node[] nodes;
 foreach(i; 0 .. n) nodes ~= new Node(i);

 int m = read.to!int;
	
 string s = readln.chomp;
 foreach(i, c; s) nodes[i].value = c;
	
 foreach(i; 0 .. m){
  int u = read.to!int - 1, v = read.to!int - 1;
  nodes[u].nodes ~= nodes[v];
  nodes[v].nodes ~= nodes[u];
 }
	
 long ans = 0;
 foreach(nd1; nodes){
  if(nd1.value != 'P') continue;
  if(! nd1.hasMemo){
   nd1.memo = 0;
   foreach(nd2; nd1.nodes){
    if(nd2.value != 'D') continue;
    if(! nd2.hasMemo){
     nd2.memo = 0;
     foreach(nd3; nd2.nodes){
      if(nd3.value != 'C') continue;
      if(! nd3.hasMemo){
       nd3.memo = 0;
       foreach(nd4; nd3.nodes){
        if(nd4.value != 'A') continue;
        nd3.memo += 1;
        nd3.memo  %= MOD;
       }
       nd3.hasMemo = 1;
      }
      nd2.memo += nd3.memo;
      nd2.memo %= MOD;
     }
     nd2.hasMemo = 1;
    }
    nd1.memo += nd2.memo;
    nd1.memo %= MOD;
   }
   nd1.hasMemo = 1;
  }
  ans += nd1.memo;
  ans %= MOD;
 }
	
 ans.writeln;
}
0