結果

問題 No.147 試験監督(2)
ユーザー kyunakyuna
提出日時 2019-09-24 06:29:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 639 ms / 2,000 ms
コード長 3,000 bytes
コンパイル時間 988 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 08:43:17
合計ジャッジ時間 4,506 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 637 ms
4,348 KB
testcase_01 AC 636 ms
4,348 KB
testcase_02 AC 639 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

//-----------------------
const int MOD = (int)1e9 + 7;
struct mint { int n; mint(int n_ = 0) : n(n_ % MOD) { if (n < 0) n += MOD; } };
mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a.n; }
mint operator*(mint a, mint b) { return 1LL * a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
ostream &operator<<(ostream &os, mint a) { return os << a.n; }
istream &operator>>(istream &is, mint& a) { return is >> a.n; }
mint inv(mint x) { long long a = x.n, b = MOD, u = 1, v = 0;
    while (b) { long long t = a/b; swap((a -= t*b), b); swap((u -= t*v), v); }
    return mint(u); }
mint operator^(mint a, long long n) { mint r = 1;
    while (n) { if (n & 1) r *= a; a *= a; n >>= 1; } return r; }
bool operator<(const mint &a, const mint &b) { return a.n < b.n; }
//-----------------------

template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) {
    for (auto &vi: vec) os << vi << " "; return os;
}
template<class T> struct Matrix {
    vector<vector<T>> val;
    Matrix(int n = 1, int m = 1, T x = 0) { val.assign(n, vector<T>(m, x)); }
    size_t size() const { return val.size(); }
    vector<T>& operator[](int i) { return val[i]; }
    const vector<T>& operator[](int i) const { return val[i]; }
    friend ostream& operator<<(ostream& os, const Matrix<T> M) {
        for (int i = 0; i < M.size(); ++i) os << M[i] << " \n"[i != M.size() - 1];
        return os;
    }
};
template<class T> Matrix<T> operator^(Matrix<T> A, long long n) {
    Matrix<T> R(A.size(), A.size());
    for (int i = 0; i < A.size(); ++i) R[i][i] = 1;
    while (n > 0) { if (n & 1) R = R * A; A = A * A; n >>= 1; }
    return R;
}
template<class T> Matrix<T> operator*(const Matrix<T>& A, const Matrix<T>& B) {
    Matrix<T> R(A.size(), B[0].size());
    for (int i = 0; i < A.size(); ++i) for (int j = 0; j < B[0].size(); ++j)
        for (int k = 0; k < B.size(); ++k) R[i][j] += A[i][k] * B[k][j];
    return R;
}
template<class T> T rec3(T a, T b, long long n, T x0 = 0, T x1 = 1) {
    if (n == 0) return x0;
    Matrix<T> A(2, 2);
    A[0][0] = a; A[0][1] = b;   // x[i + 2] = a * x[i + 1] + b * x[i]
    A[1][0] = 1; A[1][1] = 0;
    auto pow = A ^ (n - 1);
    return pow[0][0] * x1 + pow[0][1] * x0;
}
template<class T> T fib(long long n, T x0 = 0, T x1 = 1) {
    return rec3(T(1), T(1), n, x0, x1);
}

long long modstr(const string &s, long long mod) {
    long long a = 0;
    for (auto &c: s) a = (a * 10 + c - '0') % mod;
    return a;
}

int main() {
    mint res = 1;
    int n; cin >> n;
    while (n--) {
        long long c; string d; cin >> c >> d;
        res *= fib<mint>(c + 2) ^ (modstr(d, MOD - 1) + MOD - 1);
    }
    cout << res << endl;
    return 0;
}
0