結果

問題 No.265 数学のテスト
ユーザー yuki2006yuki2006
提出日時 2015-08-07 21:26:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,237 bytes
コンパイル時間 3,983 ms
コンパイル使用メモリ 74,168 KB
実行使用メモリ 57,780 KB
最終ジャッジ日時 2023-09-25 05:58:03
合計ジャッジ時間 11,062 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 190 ms
56,436 KB
testcase_01 AC 185 ms
56,148 KB
testcase_02 WA -
testcase_03 AC 154 ms
57,780 KB
testcase_04 AC 151 ms
55,604 KB
testcase_05 AC 191 ms
56,660 KB
testcase_06 AC 156 ms
55,512 KB
testcase_07 AC 184 ms
56,052 KB
testcase_08 AC 184 ms
56,436 KB
testcase_09 AC 152 ms
56,448 KB
testcase_10 AC 152 ms
55,960 KB
testcase_11 AC 162 ms
56,220 KB
testcase_12 AC 126 ms
55,552 KB
testcase_13 AC 138 ms
55,760 KB
testcase_14 AC 138 ms
56,412 KB
testcase_15 AC 122 ms
55,948 KB
testcase_16 AC 138 ms
55,816 KB
testcase_17 AC 121 ms
55,816 KB
testcase_18 AC 121 ms
55,944 KB
testcase_19 AC 127 ms
55,812 KB
testcase_20 AC 126 ms
55,716 KB
testcase_21 AC 125 ms
55,960 KB
testcase_22 AC 143 ms
54,404 KB
testcase_23 AC 121 ms
55,828 KB
testcase_24 AC 120 ms
55,948 KB
testcase_25 AC 144 ms
53,892 KB
testcase_26 AC 122 ms
56,180 KB
testcase_27 AC 124 ms
55,816 KB
testcase_28 AC 133 ms
55,776 KB
testcase_29 AC 122 ms
55,920 KB
testcase_30 AC 130 ms
56,032 KB
testcase_31 AC 122 ms
55,852 KB
testcase_32 AC 120 ms
53,924 KB
testcase_33 AC 122 ms
55,920 KB
testcase_34 AC 120 ms
56,156 KB
testcase_35 AC 121 ms
54,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Yuki265 {

    int pow(int s, int p) {
        int tmp = 1;
        for (int i = s; i <= p; i++) {
            tmp *= i;
        }
        return tmp;
    }

    void endTerm(int[] consts, int dimension, int level, int term) {
        int t = dimension - level;
        int l = term;
        if (t < 0) {
            l *= 0;
            t = 0;
        } else {
            l *= pow(t + 1, dimension);
        }

        consts[t] += l;
    }

    public Yuki265() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int d = scanner.nextInt();
        String S = scanner.next();

        int term = 1;
        int level = 0;
        int dimension = 0;
        boolean lastTerm = false;
        int[] consts = new int[d + 1];
        for (int i = 0; i < N; i++) {
            final char c = S.charAt(i);
            if (Character.isDigit(c)) {
                term *= c - '0';
                lastTerm = true;
            } else if (c == 'x') {
                dimension++;
                lastTerm = true;

            } else if (c == '+') {
                if (lastTerm) {
                    endTerm(consts, dimension, level, term);
                }
                term = 1;
                dimension = 0;
            } else if (c == 'd') {
                level++;
                lastTerm = false;

            } else if (c == '}') {
                if (lastTerm) {
                    endTerm(consts, dimension, level, term);
                }
                level--;
                term = 1;
                // x*d(x) がないので リセットする。
                dimension = 0;
                lastTerm = false;
            } else if (c == '{') {
                lastTerm = false;

            } else if (c == '*') {
                lastTerm = false;

            }
        }
        if (lastTerm) {
            endTerm(consts, dimension, level, term);
        }


        for (int i = 0; i < d + 1; i++) {
            if (i > 0) {
                System.out.print(" ");
            }
            System.out.print(consts[i]);

        }
    }

    public static void main(String[] args) {
        Yuki265 hoge = new Yuki265();
    }
}
0