結果

問題 No.1081 和の和
ユーザー kibunakibuna
提出日時 2020-06-19 21:25:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,161 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 167,824 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-16 13:13:45
合計ジャッジ時間 2,236 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <int mod>
struct modint {
    lint v;
    modint() : v(0) {}
    modint(signed v) : v(v) {}
    modint(lint t) {
        v = t % mod;
        if (v < 0)
            v += mod;
    }

    modint pow(lint k) {
        modint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static modint add_identity() { return modint(0); }
    static modint mul_identity() { return modint(1); }
    modint inv() { return pow(mod - 2); }

    modint &operator+=(modint a) {
        v += a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    modint &operator-=(modint a) {
        v += mod - a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    modint &operator*=(modint a) {
        v = v * a.v % mod;
        return *this;
    }
    modint &operator/=(modint a) { return (*this) *= a.inv(); }

    modint operator+(modint a) const { return modint(v) += a; };
    modint operator-(modint a) const { return modint(v) -= a; };
    modint operator*(modint a) const { return modint(v) *= a; };
    modint operator/(modint a) const { return modint(v) /= a; };

    modint operator-() const { return v ? modint(mod - v) : modint(v); }

    bool operator==(const modint a) const { return v == a.v; }
    bool operator!=(const modint a) const { return v != a.v; }
    bool operator<(const modint a) const { return v < a.v; }
};
using mint = modint<mod>;
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<mint> a(n);
    for (int i = 0; i < n; ++i) {
        int aa;
        cin >> aa;
        a[i] = aa;
    }
    vector<mint> b(n);
    for (int x = 0; x < n - 1; ++x) {
        b.assign(n, 0);
        for (int i = 0; i < n - 1; ++i) {
            b[i] = a[i] + a[i + 1];
        }
        swap(a, b);
    }
    cout << a[0] << "\n";

    return 0;
}
0