結果
| 問題 |
No.147 試験監督(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-09-08 13:49:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 104 ms / 2,000 ms |
| コード長 | 1,582 bytes |
| コンパイル時間 | 498 ms |
| コンパイル使用メモリ | 59,484 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 04:58:21 |
| 合計ジャッジ時間 | 1,383 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:50:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
50 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:53:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
53 | i64 c; char d[210]; scanf("%lld%s", &c, d);
| ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#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 R = {{0, 0}, {0, 0}};
R[0][0] = (A[0][0]*B[0][0] + A[0][1]*B[1][0]) % mod;
R[0][1] = (A[0][0]*B[0][1] + A[0][1]*B[1][1]) % mod;
R[1][0] = (A[1][0]*B[0][0] + A[1][1]*B[1][0]) % mod;
R[1][1] = (A[1][0]*B[0][1] + A[1][1]*B[1][1]) % mod;
memcpy(res, R, sizeof(R));
}
void matpow(mat A, i64 n, mat res) {
mat R = {{1, 0}, {0, 1}};
for(; n>0; n>>=1) {
if(n & 1) { matmul(R, A, R); }
matmul(A, A, A);
}
memcpy(res, R, sizeof(R));
}
i64 bigint2modint(string bignum, i64 mod) {
i64 res = 0;
for(char c : bignum) {
(res *= 10) += (c - '0');
res %= mod;
}
return res ? res : mod-1;
}
i64 mod_pow(i64 a, i64 n, i64 mod) {
i64 res = 1LL;
for(i64 p=a, x=n; x>0; x>>=1) {
if(x & 1) { (res *= p) %= mod; }
(p *= p) %= mod;
}
return res;
}
int main(void) {
int n; scanf("%d", &n);
i64 res = 1;
for(int i : range(n)) {
i64 c; char d[210]; scanf("%lld%s", &c, d);
mat ma = {{1, 1}, {1, 0}};
mat powered;
matpow(ma, c+1, powered);
i64 dd = bigint2modint(d, mod-1);
(res *= mod_pow(powered[0][0], dd, mod)) %= mod;
}
printf("%d\n", int(res));
return 0;
}