結果
| 問題 |
No.147 試験監督(2)
|
| コンテスト | |
| ユーザー |
tanimani364
|
| 提出日時 | 2021-04-12 17:46:36 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,850 bytes |
| コンパイル時間 | 2,279 ms |
| コンパイル使用メモリ | 206,320 KB |
| 最終ジャッジ日時 | 2025-01-20 16:17:45 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 1 |
ソースコード
#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define fi first
#define se second
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll mod_998244353 = 998244353;
constexpr ll INF = 1LL << 60;
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
//using lll=boost::multiprecision::cpp_int;
//using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
ll mypow(ll x, ll n, const ll &p = -1)
{ //x^nをmodで割った余り
if (p != -1)
{
x =(x%p+p)%p;
}
ll ret = 1;
while (n > 0)
{
if (n & 1)
{
if (p != -1)
ret = (ret * x) % p;
else
ret *= x;
}
if (p != -1)
x = (x * x) % p;
else
x *= x;
n >>= 1;
}
return ret;
}
using namespace std;
//using namespace atcoder;
template<class T>
struct Matrix{
vector<vector<T>> mat;
Matrix(int n,int m,T val=0){
mat.assign(n,vector<T>(m,val));
}
inline vector<T>& operator[](int k){//変更するとき
return mat.at(k);
}
inline const vector<T>& operator[](int k) const{//変更しないとき
return mat.at(k);
}
Matrix I(int n){
Matrix v(n,n);
for(int i=0;i<n;++i)v[i][i]=1;
return v;
}
Matrix& operator+=(const Matrix &v){
int n=mat.size(),m=mat[0].size();
assert(n==(int)v.mat.size()&&m==(int)v.mat[0].size());
for(int i=0;i<n;++i){
for(int j=0;j<m;++j){
(*this)[i][j]+=v[i][j];
}
}
return *this;
}
Matrix& operator-=(const Matrix &v){
int n=mat.size(),m=mat[0].size();
assert(n==(int)v.mat.size()&&m==(int)v.mat[0].size());
for(int i=0;i<n;++i){
for(int j=0;j<m;++j){
(*this)[i][j]-=v[i][j];
}
}
return *this;
}
Matrix& operator*=(const Matrix &v){
int n=mat.size(),m=mat[0].size();
assert(m==(int)v.mat.size());
vector<vector<T>>work(n,vector<T>(m,0));
for(int i=0;i<n;++i){
for(int j=0;j<m;++j){
for(int k=0;k<m;++k){
work[i][j]+=(*this)[i][k]*v[k][j];
}
}
}
mat.swap(work);
return *this;
}
Matrix& operator^=(int64_t k){
int n=mat.size();
Matrix v=this->I(n);
while(k>0){
if(k&1){
v*=*this;
}
*this*=*this;
k>>=1;
}
mat.swap(v.mat);
return *this;
}
Matrix operator+(const Matrix &v) const{
return (Matrix(*this)+=v);//thisポインタを渡しているのでコピーコンストラクタが呼ばれている
}
Matrix operator-(const Matrix &v) const{
return (Matrix(*this)-=v);//thisポインタを渡しているのでコピーコンストラクタが呼ばれている
}
Matrix operator*(const Matrix &v) const{
return (Matrix(*this)*=v);//thisポインタを渡しているのでコピーコンストラクタが呼ばれている
}
Matrix operator^(const Matrix &v) const{
return (Matrix(*this)^=v);//thisポインタを渡しているのでコピーコンストラクタが呼ばれている
}
};
template<int mod>
struct Modint{
int x;
Modint():x(0){}
Modint(int64_t y):x((y%mod+mod)%mod){}
Modint &operator+=(const Modint &p){
if((x+=p.x)>=mod)
x -= mod;
return *this;
}
Modint &operator-=(const Modint &p){
if((x+=mod-p.x)>=mod)
x -= mod;
return *this;
}
Modint &operator*=(const Modint &p){
x = (1LL * x * p.x) % mod;
return *this;
}
Modint &operator/=(const Modint &p){
*this *= p.inverse();
return *this;
}
Modint operator-() const { return Modint(-x); }
Modint operator+(const Modint &p) const{
return Modint(*this) += p;
}
Modint operator-(const Modint &p) const{
return Modint(*this) -= p;
}
Modint operator*(const Modint &p) const{
return Modint(*this) *= p;
}
Modint operator/(const Modint &p) const{
return Modint(*this) /= p;
}
bool operator==(const Modint &p) const { return x == p.x; }
bool operator!=(const Modint &p) const{return x != p.x;}
Modint inverse() const{//非再帰拡張ユークリッド
int a = x, b = mod, u = 1, v = 0;
while(b>0){
int t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return Modint(u);
}
Modint pow(int64_t n) const{//繰り返し二乗法
Modint ret(1), mul(x);
while(n>0){
if(n&1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os,const Modint &p){
return os << p.x;
}
};
using modint = Modint<mod>;
using modint2= Modint<mod_998244353>;
void solve()
{
int n;
cin>>n;
Matrix<modint>A(2,2),dp(2,2);
A[0][0]=1,A[0][1]=1;
A[1][0]=1;
auto originA=A;
dp[0][0]=1,dp[1][0]=1;
modint ans=1;
rep(i,n){
ll c;
string d;
cin>>c>>d;
A^=c;
A*=dp;
modint res=A[0][0];
ll prod=0;
rep(j,d.size()){
prod*=10;
prod+=d[j]-'0';
prod%=(mod-1);
}
assert(prod>=0);
res=res.pow(prod);
ans*=res;
A=originA;
}
cout<<ans<<"\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
solve();
return 0;
}
tanimani364