結果
問題 |
No.265 数学のテスト
|
ユーザー |
![]() |
提出日時 | 2017-11-03 20:52:15 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 202 ms / 2,000 ms |
コード長 | 1,583 bytes |
コンパイル時間 | 3,283 ms |
コンパイル使用メモリ | 79,552 KB |
実行使用メモリ | 43,436 KB |
最終ジャッジ日時 | 2024-11-24 11:38:31 |
合計ジャッジ時間 | 10,106 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
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(); } }