結果

問題 No.762 PDCAパス
ユーザー Pump0129Pump0129
提出日時 2018-12-11 01:50:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 822 ms / 2,000 ms
コード長 3,497 bytes
コンパイル時間 2,755 ms
コンパイル使用メモリ 80,084 KB
実行使用メモリ 66,640 KB
最終ジャッジ日時 2024-09-16 16:00:32
合計ジャッジ時間 19,054 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
41,152 KB
testcase_01 AC 123 ms
41,460 KB
testcase_02 AC 107 ms
39,724 KB
testcase_03 AC 120 ms
41,248 KB
testcase_04 AC 120 ms
41,380 KB
testcase_05 AC 119 ms
41,012 KB
testcase_06 AC 122 ms
40,904 KB
testcase_07 AC 119 ms
40,892 KB
testcase_08 AC 119 ms
41,172 KB
testcase_09 AC 121 ms
41,084 KB
testcase_10 AC 121 ms
41,188 KB
testcase_11 AC 105 ms
39,896 KB
testcase_12 AC 115 ms
41,208 KB
testcase_13 AC 116 ms
41,252 KB
testcase_14 AC 117 ms
41,120 KB
testcase_15 AC 116 ms
39,916 KB
testcase_16 AC 125 ms
41,080 KB
testcase_17 AC 117 ms
41,080 KB
testcase_18 AC 119 ms
40,940 KB
testcase_19 AC 116 ms
41,188 KB
testcase_20 AC 116 ms
41,180 KB
testcase_21 AC 110 ms
39,728 KB
testcase_22 AC 578 ms
55,576 KB
testcase_23 AC 570 ms
55,792 KB
testcase_24 AC 677 ms
66,640 KB
testcase_25 AC 689 ms
66,304 KB
testcase_26 AC 575 ms
55,996 KB
testcase_27 AC 556 ms
56,392 KB
testcase_28 AC 741 ms
62,964 KB
testcase_29 AC 822 ms
62,244 KB
testcase_30 AC 736 ms
61,084 KB
testcase_31 AC 699 ms
61,076 KB
testcase_32 AC 684 ms
61,420 KB
testcase_33 AC 694 ms
59,608 KB
testcase_34 AC 688 ms
59,436 KB
testcase_35 AC 710 ms
60,160 KB
testcase_36 AC 648 ms
56,096 KB
testcase_37 AC 641 ms
56,376 KB
testcase_38 AC 631 ms
55,848 KB
testcase_39 AC 623 ms
56,292 KB
testcase_40 AC 617 ms
57,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package net.ipipip0129.yukicoder.no762;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        String[] split_str = scan.nextLine().split(" ");
        int leaf_num = Integer.parseInt(split_str[0]);
        int pass_num = Integer.parseInt(split_str[1]);

        PDCALeaf[] pdcaLeaves = new PDCALeaf[leaf_num];

        String pdca_str = scan.nextLine();

        for (int i = 0; i < leaf_num; i++) {
            switch (pdca_str.charAt(i)) {
                case 'P':
                    pdcaLeaves[i] = new PDCALeaf(PDCA.Plan, 0);
                    break;
                case 'D':
                    pdcaLeaves[i] = new PDCALeaf(PDCA.Do, 0);
                    break;
                case 'C':
                    pdcaLeaves[i] = new PDCALeaf(PDCA.Check, 0);
                    break;
                case 'A':
                    pdcaLeaves[i] = new PDCALeaf(PDCA.Act, 1);
                    break;
            }
        }

        for (int i = 0; i < pass_num; i++) {
            split_str = scan.nextLine().split(" ");
            int a_num = Integer.parseInt(split_str[0]) - 1;
            int b_num = Integer.parseInt(split_str[1]) - 1;
            PDCA a_type = pdcaLeaves[a_num].getType();
            PDCA b_type = pdcaLeaves[b_num].getType();

            if ((a_type == PDCA.Act && b_type == PDCA.Check) ||
                    (a_type == PDCA.Check && b_type == PDCA.Do) ||
                    (a_type == PDCA.Do && b_type == PDCA.Plan)) {
                pdcaLeaves[b_num].addLeaf(a_num);
            } else if ((a_type == PDCA.Check && b_type == PDCA.Act) ||
                    (a_type == PDCA.Do && b_type == PDCA.Check) ||
                    (a_type == PDCA.Plan && b_type == PDCA.Do)) {
                pdcaLeaves[a_num].addLeaf(b_num);
            }
        }

        PDCA[] check_array = new PDCA[] {PDCA.Check, PDCA.Do, PDCA.Plan};

        for (int j = 0; j < 3; j++) {
            for (int i = 0; i < leaf_num; i++) {
                if (pdcaLeaves[i].getType() == check_array[j]) {
                    long leaf_weight = pdcaLeaves[i].getWeight();
                    for (int leaf : pdcaLeaves[i].getLeaf_list()) {
                        leaf_weight += pdcaLeaves[leaf].getWeight();
                    }
                    pdcaLeaves[i].setWeight(leaf_weight);
                }
            }
        }

        long ans = 0;

        for (int i = 0; i < leaf_num; i++) {
            if (pdcaLeaves[i].getType() == PDCA.Plan) {
                ans += pdcaLeaves[i].getWeight();
            }
        }

        System.out.println(ans % 1000000007);

        scan.close();
    }
}

class PDCALeaf {

    PDCA type_pdca;
    long weight;
    List<Integer> leaf_list;

    PDCALeaf(PDCA type, int weight) {
        this.type_pdca = type;
        this.weight = weight;
        this.leaf_list = new ArrayList<>();
    }

    void addLeaf(int leaf_num) {
        leaf_list.add(leaf_num);
    }

    PDCA getType() {
        return type_pdca;
    }

    List<Integer> getLeaf_list() {
        return leaf_list;
    }

    long getWeight() {
        return weight;
    }

    public void setWeight(long weight) {
        this.weight = weight;
    }
}

enum PDCA {
    Plan,
    Do,
    Check,
    Act
}
0