結果
| 問題 |
No.265 数学のテスト
|
| コンテスト | |
| ユーザー |
t8m8⛄️
|
| 提出日時 | 2015-08-07 23:30:13 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 197 ms / 2,000 ms |
| コード長 | 1,581 bytes |
| コンパイル時間 | 3,379 ms |
| コンパイル使用メモリ | 84,068 KB |
| 実行使用メモリ | 56,920 KB |
| 最終ジャッジ日時 | 2024-07-18 05:24:53 |
| 合計ジャッジ時間 | 9,912 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
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();
long[] a = new long[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(long[] a, char[] cs) {
while (ptr < cs.length) {
if (cs[ptr] == 'd') {
ptr += 2;
long[] b = new long[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(long[] 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));}
}
t8m8⛄️