結果

問題 No.147 試験監督(2)
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-09-08 08:47:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 1,572 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 61,228 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 10:05:08
合計ジャッジ時間 2,310 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
using i64 = long long;
using mat = i64[2][2];

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

const int mod = int(1e9) + 7;

void matmul(mat a, mat b, mat res) {
  mat r0 = {{0, 0}, {0, 0}};
  r0[0][0] = (a[0][0]*b[0][0] + a[0][1]*b[1][0]) % mod;
  r0[0][1] = (a[0][0]*b[0][1] + a[0][1]*b[1][1]) % mod;
  r0[1][0] = (a[1][0]*b[0][0] + a[1][1]*b[1][0]) % mod;
  r0[1][1] = (a[1][0]*b[0][1] + a[1][1]*b[1][1]) % mod;
  memcpy(res, r0, sizeof(r0));
}

void matpow(mat a, i64 n, mat res) {
  mat r1 = {{1, 0}, {0, 1}};
  for(; n>0; n>>=1) {
    if(n & 1) { matmul(r1, a, r1); }
    matmul(a, a, a);
  }
  memcpy(res, r1, sizeof(r1));
}

i64 mod_pow(i64 a, i64 n, i64 mod) {
  i64 res = 1LL;
  for(i64 p=a; n>0; n>>=1) {
    if(n & 1) { (res *= p) %= mod; }
    (p *= p) %= mod;
  }
  return res;
}

i64 to_modint(string s, i64 mod) {
  i64 res = 0;
  for(char c : s) {
    (res *= 10) += (c - '0');
    res %= mod;
  }
  return res ? res : mod-1;
}

int main(void) {
  int n; scanf("%d", &n);
  i64 res = 1;
  for(int i : range(n)) {
    i64 c; string d; cin >> c >> d;
    mat ma = {{1, 1}, {1, 0}};
    mat powered;
    matpow(ma, c+1, powered);
    i64 y = to_modint(d, mod-1),
        z = mod_pow(powered[0][0], y, mod);
    (res *= z) %= mod;
  }
  printf("%d\n", int(res));
  return 0;
}
0