結果

問題 No.147 試験監督(2)
ユーザー 0w10w1
提出日時 2016-12-15 13:13:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 838 ms / 2,000 ms
コード長 2,068 bytes
コンパイル時間 2,755 ms
コンパイル使用メモリ 179,652 KB
実行使用メモリ 10,524 KB
最終ジャッジ日時 2023-08-20 07:32:15
合計ジャッジ時間 7,259 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;
const int MOD7 = ( int ) 1e9 + 7;

int N;
vl C;
vs D;

void init(){
  cin >> N;
  C = vl( N );
  D = vs( N );
  for( int i = 0; i < N; ++i )
    cin >> C[ i ] >> D[ i ];
}

vvi trans;
vvi s1;
vi d;

void preprocess(){
  trans = { { 0, 1 }, { 1, 1 } };
  s1 = { { 2 }, { 3 } };
  d = vi( N );
  for( int i = 0; i < N; ++i ){
    string s = D[ i ];
    int f = 0;
    for( int j = 0; j < s.size(); ++j )
      f = ( 1LL * f * 10 + s[ j ] - '0' ) % ( MOD7 - 1 );
    d[ i ] = f;
  }
}

vvi mat_mul( vvi a, vvi b ){
  vvi c = vvi( a.size(), vi( b[ 0 ].size() ) );
  for( int i = 0; i < a.size(); ++i )
    for( int j = 0; j < a[ 0 ].size(); ++j )
      for( int k = 0; k < b[ 0 ].size(); ++k )
        ( c[ i ][ k ] += 1LL * a[ i ][ j ] * b[ j ][ k ] % MOD7 ) %= MOD7;
  return c;
}

vvi mat_pow( vvi a, ll p ){
  vvi res = vvi( a.size(), vi( a.size() ) );
  for( int i = 0; i < a.size(); ++i )
    res[ i ][ i ] = 1;
  while( p ){
    if( p & 1LL )
      res = mat_mul( res, a );
    p >>= 1;
    a = mat_mul( a, a );
  }
  return res;
}

int int_pow( int v, int p ){
  int res = v != 0;
  while( p ){
    if( p & 1 )
      res = 1LL * res * v % MOD7;
    p >>= 1;
    v = 1LL * v * v % MOD7;
  }
  return res;
}

void solve(){
  int ans = 1;
  for( int i = 0; i < N; ++i )
    ans = 1LL * ans * int_pow( mat_mul( mat_pow( trans, C[ i ] - 1 ), s1 )[ 0 ][ 0 ], d[ i ] ) % MOD7;
  cout << ans << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0