結果

問題 No.265 数学のテスト
ユーザー maine_honzukimaine_honzuki
提出日時 2021-05-06 10:18:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,738 bytes
コンパイル時間 2,128 ms
コンパイル使用メモリ 203,772 KB
実行使用メモリ 7,668 KB
最終ジャッジ日時 2023-10-12 03:32:47
合計ジャッジ時間 4,437 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//https://ncode.syosetu.com/n4830bu/001/
#include <bits/stdc++.h>
using namespace std;
using State = string::const_iterator;
using ll = long long;

int N, d;
string S;

vector<ll> expression(State& begin);
vector<ll> term(State& begin);
int number(State& begin);

vector<ll> add(vector<ll> a, vector<ll> b) {
    for (int i = 0; i <= d; i++) {
        a[i] += b[i];
    }
    return a;
}
vector<ll> mul(vector<ll> a, ll b) {
    if (b >= 0)
        for (int i = 0; i <= d; i++) {
            a[i] *= b;
        }
    else {
        for (int i = d; i >= 1; i--) {
            a[i] = a[i - 1];
        }
        a[0] = 0;
    }
    return a;
}
vector<ll> dif(vector<ll> a) {
    for (int i = 0; i < d; i++) {
        a[i] = a[i + 1] * (i + 1);
    }
    a[d] = 0;
    return a;
}

vector<ll> expression(State& begin) {
    vector<ll> ret = term(begin);
    while (*begin == '+') {
        begin++;
        ret = add(ret, term(begin));
    }
    return ret;
}

vector<ll> term(State& begin) {
    vector<ll> ret(d + 1);
    int n = number(begin);
    if (n == -2) {
        begin++;
        ret = dif(expression(begin));
        begin++;
        return ret;
    }
    if (n >= 0)
        ret[0] = n;
    else if (n == -1)
        ret[1] = 1;
    while (*begin == '*') {
        begin++;
        ret = mul(ret, number(begin));
    }
    return ret;
}

int number(State& begin) {
    auto c = *(begin++);
    if (isdigit(c))
        return c - '0';
    else if (c == 'x')
        return -1;
    else if (c == 'd')
        return -2;
    assert(false);
}


int main() {
    cin >> N >> d >> S;
    State state = S.begin();
    auto maine = expression(state);
    for (int i = 0; i <= d; i++) {
        cout << maine[i] << " \n"[i == d];
    }
}
0