結果

問題 No.265 数学のテスト
ユーザー yuki2006yuki2006
提出日時 2015-08-07 21:29:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 2,245 bytes
コンパイル時間 4,991 ms
コンパイル使用メモリ 74,748 KB
実行使用メモリ 56,540 KB
最終ジャッジ日時 2023-08-16 01:59:33
合計ジャッジ時間 11,431 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 178 ms
56,376 KB
testcase_01 AC 179 ms
56,484 KB
testcase_02 AC 180 ms
56,460 KB
testcase_03 AC 154 ms
55,880 KB
testcase_04 AC 158 ms
56,220 KB
testcase_05 AC 176 ms
56,468 KB
testcase_06 AC 154 ms
56,220 KB
testcase_07 AC 175 ms
56,540 KB
testcase_08 AC 179 ms
56,208 KB
testcase_09 AC 154 ms
55,688 KB
testcase_10 AC 157 ms
55,864 KB
testcase_11 AC 184 ms
56,140 KB
testcase_12 AC 128 ms
56,124 KB
testcase_13 AC 142 ms
56,084 KB
testcase_14 AC 140 ms
56,180 KB
testcase_15 AC 127 ms
55,768 KB
testcase_16 AC 140 ms
56,236 KB
testcase_17 AC 123 ms
56,380 KB
testcase_18 AC 124 ms
56,120 KB
testcase_19 AC 126 ms
56,212 KB
testcase_20 AC 127 ms
56,092 KB
testcase_21 AC 123 ms
53,768 KB
testcase_22 AC 141 ms
55,776 KB
testcase_23 AC 122 ms
55,972 KB
testcase_24 AC 123 ms
56,100 KB
testcase_25 AC 147 ms
56,116 KB
testcase_26 AC 125 ms
56,172 KB
testcase_27 AC 123 ms
55,572 KB
testcase_28 AC 133 ms
56,264 KB
testcase_29 AC 125 ms
55,948 KB
testcase_30 AC 132 ms
53,848 KB
testcase_31 AC 124 ms
55,880 KB
testcase_32 AC 126 ms
55,852 KB
testcase_33 AC 124 ms
55,688 KB
testcase_34 AC 122 ms
55,824 KB
testcase_35 AC 123 ms
55,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Yuki265 {

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

    void endTerm(long[] consts, int dimension, int level, long term) {
        int t = dimension - level;
        long 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();

        long term = 1;
        int level = 0;
        int dimension = 0;
        boolean lastTerm = false;
        long[] consts = new long[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