結果

問題 No.762 PDCAパス
ユーザー tentententen
提出日時 2023-02-16 08:28:31
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,681 bytes
コンパイル時間 3,185 ms
コンパイル使用メモリ 88,148 KB
実行使用メモリ 74,200 KB
最終ジャッジ日時 2023-09-25 14:05:04
合計ジャッジ時間 14,184 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,424 KB
testcase_01 AC 44 ms
49,392 KB
testcase_02 AC 44 ms
49,372 KB
testcase_03 AC 43 ms
49,316 KB
testcase_04 AC 43 ms
49,520 KB
testcase_05 AC 45 ms
49,424 KB
testcase_06 AC 44 ms
49,492 KB
testcase_07 AC 45 ms
49,520 KB
testcase_08 AC 44 ms
49,768 KB
testcase_09 AC 45 ms
49,576 KB
testcase_10 AC 44 ms
49,384 KB
testcase_11 AC 44 ms
49,800 KB
testcase_12 AC 45 ms
49,396 KB
testcase_13 AC 46 ms
49,352 KB
testcase_14 AC 45 ms
49,708 KB
testcase_15 AC 46 ms
49,520 KB
testcase_16 AC 46 ms
49,388 KB
testcase_17 AC 44 ms
49,480 KB
testcase_18 AC 45 ms
49,460 KB
testcase_19 AC 45 ms
49,648 KB
testcase_20 AC 44 ms
49,388 KB
testcase_21 AC 44 ms
49,540 KB
testcase_22 AC 257 ms
59,948 KB
testcase_23 AC 262 ms
60,020 KB
testcase_24 AC 406 ms
74,000 KB
testcase_25 AC 404 ms
73,524 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 492 ms
74,200 KB
testcase_29 AC 489 ms
74,188 KB
testcase_30 AC 459 ms
69,380 KB
testcase_31 AC 439 ms
66,960 KB
testcase_32 AC 476 ms
67,676 KB
testcase_33 AC 407 ms
64,740 KB
testcase_34 AC 408 ms
65,144 KB
testcase_35 AC 397 ms
65,032 KB
testcase_36 AC 351 ms
62,300 KB
testcase_37 AC 357 ms
63,100 KB
testcase_38 AC 349 ms
62,668 KB
testcase_39 AC 334 ms
63,768 KB
testcase_40 AC 334 ms
63,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        char[] types = sc.next().toCharArray();
        ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            graph.get(a).add(b);
            graph.get(b).add(a);
        }
        long[] pCounts = new long[n];
        long[] aCounts = new long[n];
        for (int i = 0; i < n; i++) {
            if (types[i] == 'D') {
                for (int x : graph.get(i)) {
                    if (types[x] == 'P') {
                        pCounts[i]++;
                    }
                }
            } else if (types[i] == 'C') {
                for (int x : graph.get(i)) {
                    if (types[x] == 'A') {
                        aCounts[i]++;
                    }
                }
            }
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            if (types[i] == 'D') {
                for (int x : graph.get(i)) {
                    ans += pCounts[i] * aCounts[x];
                }
            }
        }
        System.out.println(ans);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0