結果

問題 No.265 数学のテスト
ユーザー nanasilinanasili
提出日時 2015-09-09 09:36:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,750 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 87,844 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 02:06:54
合計ジャッジ時間 2,309 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 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,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 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,384 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;
typedef vector <pair<ll, int> > VPI;

#define ST -1
#define EN -2

char s[50001];
int n, d;
ll ans[11];

VPI calc(VPI a) {
  VPI ret;

  int cnt = 0;
  for (int p = 0; p < a.size(); p++) {
    if (a[p].first == ST) {
      cnt++;
    }else if (a[p].second == EN) {
      cnt--;
    }else {
      ll t = 1;
      for (int i = 0; i < cnt; i++) {
	t *= a[p].second;
	if (t == 0) break;
	a[p].second--;
      }
      if (t) ret.emplace_back(a[p].first*t, a[p].second);
    }
  }

  return ret;
}

VPI henkan(char *s) {
  VPI ret;
  int t = 1, b = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'd') {
      t = 1; b = 0;
      ret.emplace_back(ST, ST);
    }else if (s[i] == '}') {
      t = 1; b = 0;
      ret.emplace_back(EN, EN);
    }
    if (isdigit(s[i])) {
      t *= s[i]-'0';
      if ((i+1 < n && s[i+1] != '*') || i+1 >= n) {
	ret.emplace_back(t, b);
	t = 1; b = 0;
      }
    }else if (s[i] == 'x') {
      b++;
      if ((i+1 < n && s[i+1] != '*') || i+1 >= n) {
	ret.emplace_back(t, b);
	t = 1; b = 0;
      }
    }
  }
  return ret;
}

int main() {
  scanf("%d", &n);
  scanf("%d", &d);
  scanf("%s", s);

  VPI t = calc(henkan(s));

  for (int i = 0; i < t.size(); i++) {
    ans[t[i].second] += t[i].first;
  }

  for (int i = 0; i < d; i++) {
    printf("%lld ", ans[i]);
  }
  printf("%lld\n", ans[d]);

  return 0;
}
0