結果

問題 No.265 数学のテスト
コンテスト
ユーザー y_mazun
提出日時 2015-08-07 22:48:16
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,255 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 638 ms
コンパイル使用メモリ 88,892 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-18 10:48:40
合計ジャッジ時間 1,679 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

typedef long long ll;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <map>
#include <iostream>
#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;


char s[50000 + 100];
int n, d;

pair<int, ll> parseTerm(int &pos){
  int x = 0;
  ll i = 1;

  for(; pos < n; pos++){
    if(s[pos] == 'x'){
      x++;
    }else if(isdigit(s[pos])){
      i *= s[pos] - '0';
    }else if(s[pos] == '*'){
    }else{
      break;
    }
  }
  return make_pair(x, i);
}

vector<ll> parse(int &pos){
  vector<ll> ret(d + 1);

  while(pos < n){
    const char c = s[pos];
    // printf("%d: %c\n", pos, c);

    if(c == 'd'){
      pos += 2; // d{
      const vector<ll> tmp = parse(pos);
      pos += 1; // }
      REP(i,d) ret[i] += (i + 1) * tmp[i + 1];
    }else if(isdigit(c) || c == 'x'){
      const pair<int, ll> tmp = parseTerm(pos);
      ret[tmp.first] += tmp.second;
    }else{
      break;
    }

    if(pos < n && s[pos] == '+') pos++;
  }

  return ret;
}

vector<ll> parse(){
  int pos = 0;
  return parse(pos);
}

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

  const vector<ll> ret = parse();
  REP(i,d+1) printf("%lld ", ret[i]); puts("");
  return 0;
}
0