結果

問題 No.147 試験監督(2)
ユーザー DAyamaCTFDAyamaCTF
提出日時 2017-09-21 03:27:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 814 ms / 2,000 ms
コード長 2,218 bytes
コンパイル時間 1,612 ms
コンパイル使用メモリ 165,724 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-25 21:30:44
合計ジャッジ時間 5,235 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 812 ms
12,288 KB
testcase_01 AC 814 ms
12,416 KB
testcase_02 AC 812 ms
12,416 KB
testcase_03 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

const long long M=1e9+7;
typedef vector<long long> vec;
typedef vector<vec> mat;
struct Matrix{
  int N;
  mat a;
  Matrix(int n){
    N=n;
    a=mat(N,vec(N));
    for(int i=0;i<N;i++)a[i][i]=1;
  }
  Matrix pow(long long b) const {
    Matrix res(N);
    Matrix d(N);
    for(int i=0;i<N;i++)for(int j=0;j<N;j++)d[i][j]=a[i][j];
    for(;b>0;b>>=1,d=d*d)if(b&1)res=d*res;
    return res;
  }
  Matrix operator+(const Matrix& r) const {
    Matrix s(N);
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        s[i][j]=(a[i][j]+r.a[i][j])%M;
      }
    }
    return s;
  }
  Matrix operator*(const Matrix& r) const {
    Matrix s(N);
    for(int i=0;i<N;i++)s[i][i]=0;
    for(int i=0;i<N;i++){
      for(int k=0;k<N;k++){
        for(int j=0;j<N;j++){
          s[i][j]=(s[i][j]+a[i][k]*r.a[k][j])%M;
        }
      }
    }
    return s;
  }

  vector<long long>& operator[](int i){
    return a[i];
  }
};

ll fib(ll num){
  Matrix m(2);
  m.a[0][0]=1; m.a[0][1]=1;
  m.a[1][0]=1; m.a[1][1]=0;
  Matrix res=m.pow(num+1);
  return res[0][0]%M;
}

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%M;
    a=a*a%M;
    n>>=1;
  }
  return res;
}

ll n;
ll c[30001],d[30001];
string ds[30001];

int main(){
  cin>>n;
  rep(i,n){
    cin>>c[i]>>ds[i];
    ll sum=0;
    rep(j,ds[i].size()){
      sum*=10;
      sum+=(ds[i][j]-'0');
      sum%=M-1;
    }
    d[i]=sum;
    //dbg(d[i]);
  }

  ll res=1;
  rep(i,n){
    //dbg(fib(c[i]));
    if(fib(c[i])==0){
      cout<<0<<endl;
      return 0;
    }
    res=res*mod_pow(fib(c[i]),d[i])%M;
  }
  cout<<res<<endl;

	return 0;
}
0