結果

問題 No.265 数学のテスト
ユーザー re_re0101
提出日時 2021-10-27 07:52:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,892 bytes
コンパイル時間 5,577 ms
コンパイル使用メモリ 197,116 KB
最終ジャッジ日時 2025-01-25 07:39:16
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 13 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl>vvl;
typedef vector<vvl>vvvl;
typedef vector<vvvl>vvvvl;
typedef vector<vvvvl>vvvvvl;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<vvi>vvvi;
typedef vector<vvvi>vvvvi;
typedef vector<vvvvi>vvvvvi;
typedef pair<ll,ll> P;
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
typedef string::const_iterator State;

ll exp(ll n,ll r){if(r==0)return 1;return n*exp(n,r-1);}

// 構文解析
template<typename T>
struct Parser{
    bool error;// ヤバイ時trueに
    Parser():error(false){}
 
    // 四則演算
    T expression(string &s,int &p){
        vl vec;
        if(s[p]=='d'){
            vec=factor(s,p);
        }
        else {
            // cout<<p<<endl;
            vec=term(s,p);
            // debug(vec);
            // cout<<p<<endl;
        }
        while(p<(int)s.size()){
            if(s[p]=='+'){
                p++;
                // debug(vec);
                vl res=factor(s,p);
                // debug(res);
                rep(i,11){
                    vec[i]+=res[i];
                }
                continue;
            }
            break;
        }
        // debug(vec);
        return vec;
    }
 
    // 乗除
    T term(string &s,int &p){
        vl vec(11);
        if(s[p]=='x'){
            vec[1]=1;
        }
        else vec[0]=s[p]-'0';
        p++;
        while(p<(int)s.size()){
            if(s[p]=='*'){
                p++;
                if(s[p]=='x'){
                    for(ll i=10;i>=1;i--){
                        vec[i]=vec[i-1];
                    }
                    vec[0]=0;
                }
                else {
                    rep(i,11)vec[i]*=s[p]-'0';
                }
                p++;
                continue;
            }
            break;
        }
        // debug(vec);
        return vec;
    }
 
    // d{} or x*x+3
    T factor(string &s,int &p){
        T res(11);
        if(s[p]=='d'){
            p+=2;
            vl vec=factor(s,p);
            rep(i,10)res[i]=vec[i+1]*(i+1);
            p++;
        }else{
            return expression(s,p);
        }
        return res;
    }
 
    // 数,intのみならこれでいい.
    // int以外の数を受け取る場合は適宜編集すること
    // T number(string &s,int &p){
    //     T vec(11);
    //     if(isdigit(s[p]));
    //     else {
    //         vec[0]=
    //     }
    //     return res;
    // }
 
 
    T execute(string &s){
        int p=0;
        error=false;
        return expression(s,p);
    }
};

int main(){
    
    //サイズ11のvectorで表す
    ll a,b;cin>>a>>b;
    Parser<vl>ps;
    string s;cin>>s;
    vl vec=ps.execute(s);
    rep(i,b+1){
        cout<<vec[i]<<" ";
    }
    cout<<endl;
}
0