結果
| 問題 | No.762 PDCAパス |
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2019-12-30 09:40:30 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 927 ms / 2,000 ms |
| コード長 | 1,638 bytes |
| 記録 | |
| コンパイル時間 | 5,164 ms |
| コンパイル使用メモリ | 77,712 KB |
| 実行使用メモリ | 55,076 KB |
| 最終ジャッジ日時 | 2024-11-07 18:46:39 |
| 合計ジャッジ時間 | 24,090 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
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[a]++;
}
} 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