結果
| 問題 | 
                            No.147 試験監督(2)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             latte0119
                         | 
                    
| 提出日時 | 2016-05-26 00:15:42 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 333 ms / 2,000 ms | 
| コード長 | 2,375 bytes | 
| コンパイル時間 | 1,009 ms | 
| コンパイル使用メモリ | 91,240 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-07 14:33:13 | 
| 合計ジャッジ時間 | 3,025 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:93:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   93 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
main.cpp:99:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   99 |         scanf("%lld%s", &C, D);
      |         ~~~~~^~~~~~~~~~~~~~~~~
            
            ソースコード
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<cstdio>
#include<algorithm>
#include<vector>
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<sstream>
#include<bitset>
#include<numeric>
#include<climits>
#include<cassert>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
template<typename A,typename B>inline void chmin(A &a, B b) { if (a > b)a = b; }
template<typename A,typename B>inline void chmax(A &a, B b) { if (a < b)a = b; }
template<int MOD>
class kitamasa_hou {
    int K;
    vector<long long>A, D;
    vector<long long>advance(vector<long long>x) {
        rotate(x.begin(), x.end() - 1, x.end());
        for (int i = 1; i<x.size(); i++)x[i] = (x[i] + x[0] * D[i]) % MOD;
        return x;
    }
    vector<long long>advance2(vector<long long>x) {
        vector<long long>y = x, z(K, 0);
        for (int i = 0; i<K; i++) {
            for (int j = 0; j<K; j++)z[j] = (z[j] + x[j] * y[i]) % MOD;
            x = advance(x);
        }
        return z;
    }
public:
    kitamasa_hou(int K, vector<long long>A, vector<long long>D)
        :K(K), A(A.begin(), A.end()), D(D.begin(), D.end()) {}
    ll query(ll N) {
        assert(K);
        vector<long long>x = D;
        if (N<K)return A[N];
        ll n = K;
        int p;
        [&]() {
            for (;; n++) {
                for (p = 0; N >> p; p++)if ((N >> p) == n)return;
                x = advance(x);
            }
        }();
        for (p--; p >= 0; p--) {
            x = advance2(x);
            if (N >> p & 1)x = advance(x);
        }
        ll ret = 0;
        for (int i = 0; i<K; i++)ret = (ret + x[i] * A[i]) % MOD;
        return ret;
    }
};
const int mod = 1000000007;
ll modpow(ll n,ll m){
    if(n==0)return 0;
    ll ret = 1;
    while (m) {
        if (m & 1)ret = ret*n%mod;
        n = n*n%mod;
        m >>= 1;
    }
    return ret;
}
int main() {
    ll ans = 1;
    int N;
    scanf("%d", &N);
    kitamasa_hou<mod>fib(2, { 1,2 }, { 1,1 });
    for (int i = 0; i < N;i++) {
        ll C;
        char D[210];
        scanf("%lld%s", &C, D);
        ll d = 0;
        for (int j = 0; D[j]; j++)d = (d * 10 + D[j] - '0') % (mod-1);
        ans = ans*modpow(fib.query(C), d) % mod;
    }
    cout << ans << endl;
    return 0;
}
            
            
            
        
            
latte0119