結果
| 問題 |
No.762 PDCAパス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-27 20:58:28 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 2,000 ms |
| コード長 | 896 bytes |
| コンパイル時間 | 83 ms |
| コンパイル使用メモリ | 5,120 KB |
| 実行使用メモリ | 9,216 KB |
| 最終ジャッジ日時 | 2024-11-29 14:36:26 |
| 合計ジャッジ時間 | 3,309 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
local ior = io.read
local n, m = ior("*n", "*n", "*l")
local s = {}
local d_to_p = {}
local c_to_a = {}
local dc = {}
local str = ior()
for i = 1, n do
s[i] = str:sub(i, i)
d_to_p[i] = 0
c_to_a[i] = 0
end
for i = 1, m do
local a, b = ior("*n", "*n")
if(s[a] == "D" and s[b] == "P") then d_to_p[a] = d_to_p[a] + 1
elseif(s[b] == "D" and s[a] == "P") then d_to_p[b] = d_to_p[b] + 1
elseif(s[a] == "C" and s[b] == "A") then c_to_a[a] = c_to_a[a] + 1
elseif(s[b] == "C" and s[a] == "A") then c_to_a[b] = c_to_a[b] + 1
elseif(s[a] == "D" and s[b] == "C") then
local tmp = {}
tmp.d, tmp.c = a, b
table.insert(dc, tmp)
elseif(s[b] == "D" and s[a] == "C") then
local tmp = {}
tmp.d, tmp.c = b, a
table.insert(dc, tmp)
end
end
local sum = 0
for k, v in pairs(dc) do
local d, c = v.d, v.c
sum = (sum + d_to_p[d] * c_to_a[c]) % 1000000007
end
print(sum)