結果

問題 No.265 数学のテスト
ユーザー te-shte-sh
提出日時 2017-06-02 17:11:07
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,056 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 92,276 KB
実行使用メモリ 6,336 KB
最終ジャッジ日時 2023-09-03 13:55:04
合計ジャッジ時間 2,089 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,336 KB
testcase_01 AC 5 ms
4,636 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

const re = r"d\{[1-9x\+\*]\}";

void main()
{
  auto n = readln.chomp.to!size_t;
  auto d = readln.chomp.to!size_t;
  auto s = readln.chomp;

  long[] calc(ref size_t i)
  {
    auto ai = new long[](d+1);
    auto x = 0, y = 0;

  loop: for (; i < s.length; ++i) {
      switch (s[i]) {
      case 'x':
        ++y;
        break;
      case '0','1','2','3','4','5','6','7','8','9':
        x = s[i] - '0';
        break;
      case '*':
        break;
      case '+':
        if (x == 0 && y > 0) ++ai[y];
        else ai[y] += x;
        x = 0; y = 0;
        break;
      case 'd':
        i += 2;
        auto bi = calc(i);
        auto ci = new long[](d+1);
        foreach (j; 1..d+1)
          ci[j-1] = bi[j] * j.to!int;
        ai[] += ci[];
        break;
      case '}':
        break loop;
      default:
        assert(0);
      }
    }

    if (x == 0 && y > 0) ++ai[y];
    else ai[y] += x;

    return ai;
  }

  size_t i = 0;
  writeln(calc(i).to!(string[]).join(" "));
}
0