結果

問題 No.147 試験監督(2)
ユーザー tubo28tubo28
提出日時 2015-02-12 18:18:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 498 ms / 2,000 ms
コード長 5,811 bytes
コンパイル時間 1,520 ms
コンパイル使用メモリ 161,092 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 00:05:36
合計ジャッジ時間 4,160 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> istream & operator>>(istream & is, vector<T> &);
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
    template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _it(istream &, tuple<T...> &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _it(istream & is, tuple<T...> & t){ is >> get<n>(t); _it<n+1>(is, t); }
template<class...T> istream & operator>>(istream & is, tuple<T...> & t){ _it<0>(is, t); return is; }
template<class T, class U> istream & operator<<(istream & is, pair<T,U> & p){ return is >> p.first >> p.second; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> istream & operator>>(istream & is, vector<T> & v){ rep(i,v.size()) is >> v[i]; return is; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif

#define mintCR mint const &
template<int M>
struct mint {
    int x;
    explicit mint()
        : x(0) {}
    explicit mint(int y){
        if((x=y%M+M) >= M) x-= M;
    }
    mint & operator += (mintCR m){
        if((x += m.x) >= M) x-=M;
        return *this;
    }
    mint & operator -= (mintCR m){
        if((x += M-m.x) >= M) x-=M;
        return *this;
    }
    mint & operator *= (mintCR m){
        x = 1LL*x*m.x%M;
        return *this;
    }
    mint & operator /= (mintCR m){
        x=(1LL*x*m.exp(M-2).x)%M;
        return *this;
    }
    mint operator + (mintCR m) const {
        return mint(*this) += m;
    }
    mint operator - (mintCR m) const {
        return mint(*this) -= m;
    }
    mint operator * (mintCR m) const {
        return mint(*this) *= m;
    }
    mint operator / (mintCR m) const {
        return mint(*this) /= m;
    }
    bool operator < (mintCR m) const {
        return x < m.x;
    }
    mint inv() const {
        return exp(M-2);
    }
    mint exp(long long t) const {
        /* !! 0^0 = 1 !! */
        if(x==0) return mint(0);
        mint e = *this, res = mint(1);
        for(; t; e*=e, t>>=1) if(t&1) res *= e;
        return res;
    }
};
template <int M>
ostream &operator << (ostream & os, mint<M> m){
    return os << m.x;
}

#define matCR mat const &
template<typename T>
struct mat {
    vector<vector<T>> dat;
    int height, width;
    explicit mat(int height_, int width_)
        : dat(height_, vector<T>(width_)), height(height_), width(width_){}
    vector<T> const & operator [] (int i) const {
        return dat[i];
    };
    vector<T> & operator [] (int i){
        return dat[i];
    };
    mat & operator += (matCR x){
        rep(i,height) rep(j,width) dat[i][j]+=x[i][j];
        return *this;
    }
    mat & operator -= (matCR x){
        rep(i,height) rep(j,width) dat[i][j]-=x[i][j];
        return *this;
    }
    mat & operator *= (matCR b){
        mat res(height, b.width);
        rep(i,height) rep(k,b.height) rep(j,b.width) res[i][j] += dat[i][k]*b[k][j];
        return *this = res;
    }
    mat operator + (matCR x) const {
        return mat(*this) += x;
    }
    mat operator - (matCR x) const {
        return mat(*this) -= x;
    }
    mat operator * (matCR x) const {
        return mat(*this) *= x;
    }
    bool operator < (matCR x) const {
        return dat < x.dat;
    }
    mat exp(ll t) const {
        mat e = *this, res = id(height);
        for(; t; e*=e, t>>=1) if(t&1) res *= e;
        return res;
    }
    mat trans() const {
        mat t(width, height);
        rep(i,width) rep(j,height) t[i][j] = dat[j][i];
        return t;
    }
    static mat id (int n) {
        mat res(n,n);
        rep(i,n) res[i][i] = T(1);
        return res;
    }
};

bool getIntMod(ll & x, ll M){
    char c;
    while(1){
        c = getchar();
        if(c=='-' || c==EOF || isdigit(c)) break;
    }
    if(c==EOF) return false;
    int sign = c=='-' ? -1 : 1;
    x = c=='-' ? 0 : c-'0';
    while(1){
        c = getchar();
        if(!isdigit(c)) break;
        x = x*10 + c-'0';
        x %= M;
    }
    x*=sign;
    return true;
}

bool getIntMod(int & x, ll M){
    ll y;
    bool res = getIntMod(y, M);
    x = y;
    return res;
}

int const mod = 1000000007;
typedef mint<mod> modint;
typedef mat<modint> matrix;

modint fibonacci(ll n){
    matrix a(2,2);
    a[0][0] = modint(0);
    a[0][1] = modint(1);
    a[1][0] = modint(1);
    a[1][1] = modint(1);
    matrix b(2,1);
    b[0][0] = modint(1);
    b[1][0] = modint(2);
    matrix ans = a.exp(n) * b;
    return ans[0][0];
}

int main(){
    int n;
    while(cin >> n){
        modint ans(1);
        rep(i,n){
            ll c,d;
            cin >> c;
            getIntMod(d,mod-1);
            auto x = fibonacci(c);
            dump(x);
            ans *= x.exp(d);
        }
        cout << ans << endl;
    }
}
0