結果
| 問題 |
No.147 試験監督(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-09-07 23:31:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,721 bytes |
| コンパイル時間 | 312 ms |
| コンパイル使用メモリ | 53,424 KB |
| 最終ジャッジ日時 | 2024-11-14 19:10:38 |
| 合計ジャッジ時間 | 1,032 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:11:1: error: ‘vector’ does not name a type
11 | vector<vector<i64>> matmul(vector<vector<i64>> a, vector<vector<i64>> b) {
| ^~~~~~
main.cpp:24:1: error: ‘vector’ does not name a type
24 | vector<vector<i64>> matpow(vector<vector<i64>> a, i64 n) {
| ^~~~~~
main.cpp: In function ‘int main()’:
main.cpp:63:5: error: ‘vector’ was not declared in this scope
63 | vector<vector<i64>> mat = {{1, 1}, {1, 0}};
| ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
2 | #include <algorithm>
+++ |+#include <vector>
3 | using namespace std;
main.cpp:63:22: error: expected primary-expression before ‘>>’ token
63 | vector<vector<i64>> mat = {{1, 1}, {1, 0}};
| ^~
main.cpp:63:25: error: ‘mat’ was not declared in this scope
63 | vector<vector<i64>> mat = {{1, 1}, {1, 0}};
| ^~~
main.cpp:64:13: error: ‘matpow’ was not declared in this scope
64 | i64 x = matpow(mat, c+1)[0][0],
| ^~~~~~
main.cpp:67:13: error: ‘z’ was not declared in this scope
67 | (res *= z) %= mod;
| ^
main.cpp:59:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
59 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
using i64 = long long;
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;
vector<vector<i64>> matmul(vector<vector<i64>> a, vector<vector<i64>> b) {
int p = a.size(), q = b[0].size(), r = b.size();
vector<vector<i64>> res(p, vector<i64>(q));
for(int i=0; i<p; i++) {
for(int k=0; k<r; k++) {
for(int j=0; j<q; j++) {
(res[i][j] += a[i][k] * b[k][j]) %= mod;
}
}
}
return res;
}
vector<vector<i64>> matpow(vector<vector<i64>> a, i64 n) {
int p = a.size();
vector<vector<i64>> res(p, vector<i64>(p));
for(int i=0; i<p; i++) {
for(int j=0; j<p; j++) {
res[i][j] = i==j;
}
}
for(i64 x=n; x>0; x>>=1) {
if(x & 1) { res = matmul(res, a); }
a = matmul(a, a);
}
return res;
}
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;
}
i64 to_modint(string s, i64 mod) {
i64 res = 0;
int n = s.size();
for(int i=0; i<n; i++) {
(res *= 10) += (s[i] - '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;
vector<vector<i64>> mat = {{1, 1}, {1, 0}};
i64 x = matpow(mat, c+1)[0][0],
y = to_modint(d, mod-1),
z = mod_pow(x, y, mod);
(res *= z) %= mod;
}
printf("%d\n", int(res));
return 0;
}