結果
| 問題 |
No.762 PDCAパス
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2019-12-30 09:38:02 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,638 bytes |
| コンパイル時間 | 2,865 ms |
| コンパイル使用メモリ | 78,200 KB |
| 実行使用メモリ | 55,884 KB |
| 最終ジャッジ日時 | 2024-11-07 18:41:19 |
| 合計ジャッジ時間 | 25,999 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 29 |
ソースコード
import java.util.*;
public class Main {
static final int MOD = 1000000007;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
char[] arr = sc.next().toCharArray();
long[] counts = new long[n];
ArrayList<Integer>[] lists = new ArrayList[n];
for (int i = 0; i < n; i++) {
if (arr[i] == 'D') {
lists[i] = new ArrayList<Integer>();
}
}
for (int i = 0; i < m; i++) {
int a = sc.nextInt() - 1;
int b = sc.nextInt() - 1;
if (arr[a] == 'P') {
if (arr[b] == 'D') {
counts[b]++;
}
} else if (arr[a] == 'D') {
if (arr[b] == 'P') {
counts[a]++;
} else if (arr[b] == 'C') {
lists[a].add(b);
}
} else if (arr[a] == 'C') {
if (arr[b] == 'D') {
lists[b].add(a);
} else if (arr[b] == 'A') {
counts[b]++;
}
} else if (arr[a] == 'A') {
if (arr[b] == 'C') {
counts[b]++;
}
}
}
long total = 0;
for (int i = 0; i < n; i++) {
if (arr[i] != 'D') {
continue;
}
for (int x : lists[i]) {
total += counts[i] * counts[x];
total %= MOD;
}
}
System.out.println(total);
}
}
htensai