結果

問題 No.265 数学のテスト
ユーザー t8m8⛄️t8m8⛄️
提出日時 2015-08-07 23:30:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 222 ms / 2,000 ms
コード長 1,581 bytes
コンパイル時間 4,280 ms
コンパイル使用メモリ 80,948 KB
実行使用メモリ 61,500 KB
最終ジャッジ日時 2023-09-25 06:25:53
合計ジャッジ時間 11,717 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 217 ms
61,500 KB
testcase_01 AC 217 ms
58,868 KB
testcase_02 AC 203 ms
56,620 KB
testcase_03 AC 212 ms
58,144 KB
testcase_04 AC 215 ms
58,484 KB
testcase_05 AC 197 ms
56,136 KB
testcase_06 AC 212 ms
58,192 KB
testcase_07 AC 222 ms
56,500 KB
testcase_08 AC 220 ms
56,764 KB
testcase_09 AC 213 ms
58,204 KB
testcase_10 AC 214 ms
58,540 KB
testcase_11 AC 217 ms
56,816 KB
testcase_12 AC 150 ms
55,736 KB
testcase_13 AC 164 ms
55,784 KB
testcase_14 AC 160 ms
55,980 KB
testcase_15 AC 142 ms
56,508 KB
testcase_16 AC 158 ms
56,076 KB
testcase_17 AC 128 ms
55,896 KB
testcase_18 AC 141 ms
55,956 KB
testcase_19 AC 141 ms
55,520 KB
testcase_20 AC 143 ms
55,744 KB
testcase_21 AC 139 ms
55,688 KB
testcase_22 AC 162 ms
56,072 KB
testcase_23 AC 124 ms
56,116 KB
testcase_24 AC 140 ms
56,444 KB
testcase_25 AC 165 ms
56,136 KB
testcase_26 AC 142 ms
56,276 KB
testcase_27 AC 142 ms
55,968 KB
testcase_28 AC 154 ms
56,328 KB
testcase_29 AC 143 ms
55,964 KB
testcase_30 AC 147 ms
56,196 KB
testcase_31 AC 143 ms
56,320 KB
testcase_32 AC 141 ms
56,160 KB
testcase_33 AC 142 ms
56,140 KB
testcase_34 AC 141 ms
56,236 KB
testcase_35 AC 141 ms
56,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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));}
}
0