結果

問題 No.265 数学のテスト
ユーザー nanasilinanasili
提出日時 2015-09-09 09:32:31
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,722 bytes
コンパイル時間 906 ms
コンパイル使用メモリ 87,808 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 10:12:59
合計ジャッジ時間 3,218 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 3 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,384 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<int, int> > VPI;

#define ST -1
#define EN -2

char s[50001];
int n, d;
int 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 {
      int t = 1;
      for (int i = 0; i < cnt; i++) {
	t *= a[p].second;
	a[p].second--;
      }
      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("%d ", ans[i]);
  }
  printf("%d\n", ans[d]);

  return 0;
}
0