結果
問題 |
No.265 数学のテスト
|
ユーザー |
![]() |
提出日時 | 2015-08-07 23:19:09 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,575 bytes |
コンパイル時間 | 3,777 ms |
コンパイル使用メモリ | 84,948 KB |
実行使用メモリ | 56,700 KB |
最終ジャッジ日時 | 2024-07-18 05:22:01 |
合計ジャッジ時間 | 10,060 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 WA * 1 |
ソースコード
import java.util.*; import java.io.*; import java.awt.geom.*; import java.math.*; public class No265 { static final Scanner in = new Scanner(System.in); static final PrintWriter out = new PrintWriter(System.out,false); static void solve() { int n = in.nextInt(); int d = in.nextInt(); String s = in.next(); int[] a = new int[d+1]; calc(a,s.toCharArray()); for (int i=0; i<d; i++) { out.print(a[i] + " "); } out.println(a[d]); } static int ptr = 0; static void calc(int[] a, char[] cs) { while (ptr < cs.length) { if (cs[ptr] == 'd') { ptr += 2; int[] b = new int[a.length]; calc(b,cs); d(b); for (int i=0; i<a.length; i++) { a[i] += b[i]; } }else { int dim = 0; int coe = 1; boolean f1 = false; boolean f2 = false; while (ptr < cs.length && cs[ptr] != '+') { if (cs[ptr] == 'x') { dim++; f1 = true; }else if ('1' <= cs[ptr] && cs[ptr] <= '9') { coe *= cs[ptr] - '0'; f1 = true; }else if (cs[ptr] == '}') { f2 = true; break; } ptr++; } if (f1) a[dim] += coe; if (f2) return; } ptr++; } } static void d(int[] a) { for (int i=0; i<a.length-1; i++) { a[i] = a[i+1]*(i+1); } a[a.length-1] = 0; } public static void main(String[] args) { long start = System.currentTimeMillis(); solve(); out.flush(); long end = System.currentTimeMillis(); //trace(end-start + "ms"); in.close(); out.close(); } static void trace(Object... o) { System.out.println(Arrays.deepToString(o));} }