結果
問題 | No.762 PDCAパス |
ユーザー |
![]() |
提出日時 | 2018-12-10 12:46:48 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 177 ms / 2,000 ms |
コード長 | 1,534 bytes |
コンパイル時間 | 1,098 ms |
コンパイル使用メモリ | 127,096 KB |
実行使用メモリ | 23,868 KB |
最終ジャッジ日時 | 2024-06-13 02:10:10 |
合計ジャッジ時間 | 4,923 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
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; }