結果

問題 No.265 数学のテスト
ユーザー y_mazuny_mazun
提出日時 2015-08-07 22:48:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 67,640 KB
実行使用メモリ 5,468 KB
最終ジャッジ日時 2023-08-16 01:58:44
合計ジャッジ時間 1,828 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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