結果

問題 No.265 数学のテスト
ユーザー re_re0101re_re0101
提出日時 2021-10-27 07:52:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,892 bytes
コンパイル時間 2,366 ms
コンパイル使用メモリ 197,728 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-04-16 10:05:22
合計ジャッジ時間 3,736 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,912 KB
testcase_01 AC 10 ms
10,496 KB
testcase_02 AC 5 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
5,376 KB
testcase_16 WA -
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
5,376 KB
testcase_22 WA -
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 WA -
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 WA -
testcase_29 AC 2 ms
5,376 KB
testcase_30 WA -
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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