結果
問題 | No.265 数学のテスト |
ユーザー | uafr_cs |
提出日時 | 2017-11-03 20:14:25 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,508 bytes |
コンパイル時間 | 2,646 ms |
コンパイル使用メモリ | 85,324 KB |
実行使用メモリ | 48,652 KB |
最終ジャッジ日時 | 2024-11-22 15:44:41 |
合計ジャッジ時間 | 12,992 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 865 ms
44,272 KB |
testcase_01 | AC | 654 ms
45,500 KB |
testcase_02 | AC | 240 ms
43,552 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 163 ms
42,440 KB |
testcase_18 | AC | 163 ms
42,212 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 150 ms
41,984 KB |
testcase_24 | AC | 162 ms
42,388 KB |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 163 ms
42,388 KB |
testcase_33 | AC | 163 ms
42,368 KB |
testcase_34 | AC | 162 ms
42,576 KB |
testcase_35 | AC | 163 ms
42,492 KB |
ソースコード
import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; public class Main { public static long[] make_x(int D, int deg, int a){ long[] ret = new long[D]; ret[deg] = a; return ret; } public static long[] diff(int D, long[] term){ long[] ret = new long[D]; for(int i = 1; i < D; i++){ ret[i - 1] = i * term[i]; } return ret; } public static long[] add(int D, long[] term1, long[] term2){ long[] ret = new long[D]; for(int i = 0; i < D; i++){ ret[i] = term1[i] + term2[i]; } return ret; } public static long[] parse(int D, char[] chs, int start, int last){ //System.out.println(start + " " + last + " : " + chs[start]); if(chs[start] == 'd'){ // d{ ___ } を評価する int kakko_lv = 0, kakko_start = -1, kakko_last = -1; for(int pos = start + 1; pos <= last; pos++){ if(chs[pos] == '{'){ if(kakko_lv == 0){ kakko_start = pos; } kakko_lv += 1; }else if(chs[pos] == '}'){ kakko_lv -= 1; if(kakko_lv == 0){ kakko_last = pos; break; } } } //System.out.println(kakko_start + " " + kakko_last); long[] curr_x = diff(D, parse(D, chs, kakko_start + 1, kakko_last - 1)); //System.out.println(Arrays.toString(curr_x)); if(kakko_last == last){ return curr_x; }else{ return add(D, curr_x, parse(D, chs, kakko_last + 2, last)); } }else if(chs[start] == 'x' || Character.isDigit(chs[start])){ int x_count = 0; int a_count = 1; if(chs[start] == 'x'){ x_count++; }else{ a_count = Character.getNumericValue(chs[start]); } int plus_begin = -1; for(int pos = start + 1; pos <= last; pos++){ if(chs[pos] == '+'){ plus_begin = pos; break; }else if(chs[pos] == 'x'){ x_count++; }else if(Character.isDigit(chs[pos])){ a_count += Character.getNumericValue(chs[pos]); } } final long[] curr_x = make_x(D, x_count, a_count); //System.out.println("x : " + Arrays.toString(curr_x)); if(plus_begin < 0){ return curr_x; }else{ return add(D, curr_x, parse(D, chs, plus_begin + 1, last)); } } return null; } 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[] ret = parse(D + 1, chs, 0, N - 1); for(int i = 0; i <= D; i++){ System.out.print((i == 0 ? "" : " ") + ret[i]); } System.out.println(); } }