結果

問題 No.265 数学のテスト
ユーザー omuomu
提出日時 2015-08-09 00:53:43
言語 Java19
(openjdk 21)
結果
AC  
実行時間 307 ms / 2,000 ms
コード長 1,305 bytes
コンパイル時間 2,950 ms
コンパイル使用メモリ 74,268 KB
実行使用メモリ 59,732 KB
最終ジャッジ日時 2023-08-16 02:06:35
合計ジャッジ時間 9,310 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 196 ms
58,432 KB
testcase_01 AC 307 ms
58,816 KB
testcase_02 AC 181 ms
58,840 KB
testcase_03 AC 154 ms
58,516 KB
testcase_04 AC 163 ms
58,256 KB
testcase_05 AC 184 ms
58,504 KB
testcase_06 AC 158 ms
58,172 KB
testcase_07 AC 199 ms
59,044 KB
testcase_08 AC 204 ms
59,732 KB
testcase_09 AC 158 ms
57,840 KB
testcase_10 AC 151 ms
58,024 KB
testcase_11 AC 166 ms
58,972 KB
testcase_12 AC 118 ms
55,936 KB
testcase_13 AC 147 ms
57,964 KB
testcase_14 AC 142 ms
55,800 KB
testcase_15 AC 116 ms
55,688 KB
testcase_16 AC 147 ms
56,048 KB
testcase_17 AC 119 ms
55,652 KB
testcase_18 AC 115 ms
55,972 KB
testcase_19 AC 118 ms
53,996 KB
testcase_20 AC 117 ms
56,096 KB
testcase_21 AC 115 ms
55,876 KB
testcase_22 AC 138 ms
55,504 KB
testcase_23 AC 111 ms
54,316 KB
testcase_24 AC 117 ms
55,652 KB
testcase_25 AC 158 ms
58,024 KB
testcase_26 AC 124 ms
55,716 KB
testcase_27 AC 123 ms
55,644 KB
testcase_28 AC 131 ms
55,984 KB
testcase_29 AC 119 ms
55,864 KB
testcase_30 AC 129 ms
56,172 KB
testcase_31 AC 116 ms
55,976 KB
testcase_32 AC 119 ms
56,224 KB
testcase_33 AC 118 ms
55,800 KB
testcase_34 AC 120 ms
55,888 KB
testcase_35 AC 116 ms
56,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package tmp;

import java.util.Scanner;

public class Main {

	static Scanner sc;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		solve();
	}
	static long[] ans;
	static void cast(int D,int d,long num){
		for(int j = D;j > 0;j--){
			num *= d;
			d--;
		}
		if(d < 0)return;
		ans[d] += num;
	}
		
	
	static void solve(){
		String s;
		int n;
		int l = sc.nextInt();
		n = sc.nextInt();
		n++;
		s = sc.next();
		ans = new long[n];
		
		int D = 0;
		
		for(int i = 0;i < l;i++){
			if(i < l-1 && s.substring(i,i+2).equals("d{")){
				D++;i++;continue;
			}
			if(i < l   && s.substring(i,i+1).equals("}")){
				D--; continue;
			}
			int d = 0;
			int num = 1;
			while(true){
				String c = s.substring(i,i+1);
				if(c.equals("d")){
					i--;
					break;
				}
				if(c.equals("+")){
					i++;
					continue;
				}
				if(c.equals("x")){
					d++;
				}else{
					num *= Integer.parseInt(c);
				}
				if(i == s.length()-1 || s.substring(i+1,i+2).equals("}")){
					cast(D,d,num);
					break;
				}
				c = s.substring(i + 1,i + 2);
				if(c.equals("*")){
					i += 2;
				}
				if(c.equals("+")){
					cast(D,d,num);
					i++;
					break;
				}
			}
		}
			
		for(int j = 0;j < n;j++){
			System.out.print(ans[j]);
			System.out.print(" ");
		}
		System.out.println();
	}

}
0