結果

問題 No.265 数学のテスト
コンテスト
ユーザー uafr_cs
提出日時 2017-11-03 20:52:15
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,583 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,902 ms
コンパイル使用メモリ 84,000 KB
実行使用メモリ 46,272 KB
最終ジャッジ日時 2026-05-18 11:16:30
合計ジャッジ時間 12,089 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main2 {
	
	public static long diff_count(int div, int x, long a){
		final int act_x = x - div;
		long ret_a = a;
		
		
		for(int i = x; i > act_x; i--){ ret_a *= i; }
		return ret_a;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int D = sc.nextInt();
		final char[] chs = sc.next().toCharArray();
		
		long[] answer = new long[D + 1]; 
		
		int div_level = 0;
		int x_count = 0;
		long a_count = 0;
		for(int i = 0; i < N; i++){
			
			if(chs[i] == '{'){
				div_level++;
			}else if(chs[i] == '}'){
				
				final int act_x_count = x_count - div_level;
				if(act_x_count >= 0){
					answer[act_x_count] += diff_count(div_level, x_count, a_count);
				}
				
				x_count = 0; a_count = 0;
				div_level--;
				
			}else if(chs[i] == '+'){
				
				final int act_x_count = x_count - div_level;
				if(act_x_count >= 0){
					answer[act_x_count] += diff_count(div_level, x_count, a_count);
				}
				
				x_count = 0; a_count = 0;
				
			}else if('1' <= chs[i] && chs[i] <= '9'){
				if(a_count == 0){ a_count = 1; }
				a_count *= (chs[i] - '0');
			}else if(chs[i] == 'x'){
				x_count += 1;
				if(a_count == 0){ a_count = 1; }
			}
		}
		
		final int act_x_count = x_count - div_level;
		if(act_x_count >= 0){
			answer[act_x_count] += diff_count(div_level, x_count, a_count);
		}
		
		
		for(int i = 0; i <= D; i++){
			System.out.print((i == 0 ? "" : " ") + answer[i]);
		}
		System.out.println();
	}
}
0