結果
問題 | No.147 試験監督(2) |
ユーザー | tubo28 |
提出日時 | 2015-02-12 21:28:13 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 388 ms / 2,000 ms |
コード長 | 5,611 bytes |
コンパイル時間 | 1,462 ms |
コンパイル使用メモリ | 164,612 KB |
実行使用メモリ | 6,940 KB |
最終ジャッジ日時 | 2024-06-23 19:19:33 |
合計ジャッジ時間 | 3,795 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 385 ms
6,816 KB |
testcase_01 | AC | 388 ms
6,940 KB |
testcase_02 | AC | 380 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
ソースコード
#define _CRT_SECURE_NO_WARNINGS //#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; #define all(c) (c).begin(), (c).end() #define loop(i,a,b) for(ll i=a; i<ll(b); i++) #define rep(i,b) loop(i,0,b) #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple template<class T> istream & operator>>(istream & is, vector<T> &); template<class T> ostream & operator<<(ostream & os, vector<T> const &); template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){} template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); } template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; } template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _it(istream &, tuple<T...> &){} template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _it(istream & is, tuple<T...> & t){ is >> get<n>(t); _it<n+1>(is, t); } template<class...T> istream & operator>>(istream & is, tuple<T...> & t){ _it<0>(is, t); return is; } template<class T, class U> istream & operator<<(istream & is, pair<T,U> & p){ return is >> p.first >> p.second; } template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; } template<class T> istream & operator>>(istream & is, vector<T> & v){ rep(i,v.size()) is >> v[i]; return is; } template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; } #ifdef DEBUG #define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl) #else #define dump(...) #endif #undef MCR #define MCR Mint const & template<int M> struct Mint { int x; explicit Mint() : x(0) {} explicit Mint(int y){ if((x = y%M + M) >= M) x-= M; } Mint & operator += (MCR m){ if((x += m.x) >= M) x-=M; return *this; } Mint & operator -= (MCR m){ if((x += M-m.x) >= M) x-=M; return *this; } Mint & operator *= (MCR m){ x = 1LL * x * m.x % M; return *this; } Mint & operator /= (MCR m){ x = (1LL * x * m.exp(M-2).x) % M; return *this; } Mint operator + (MCR m) const { return Mint(*this) += m; } Mint operator - (MCR m) const { return Mint(*this) -= m; } Mint operator * (MCR m) const { return Mint(*this) *= m; } Mint operator / (MCR m) const { return Mint(*this) /= m; } bool operator < (MCR m) const { return x < m.x; } Mint inv() const { return exp(M-2); } Mint exp(long long t) const { /* !! default 0^0 = 1 !! */ if(x==0) return Mint(0); Mint e = *this, res = Mint(1); for(; t; e*=e, t>>=1) if(t&1) res *= e; return res; } }; template <int M> ostream &operator << (ostream & os, Mint<M> m){ return os << m.x; } #undef MCR #define MCR Mat const & template<typename T> struct Mat { unique_ptr<T[]> dat; int height, width; explicit Mat(int height_, int width_) : dat(new T[height_*width_]), height(height_), width(width_) { } Mat(MCR m){ *this = m; } Mat & operator = (MCR m) { width = m.width; height = m.height; dat = unique_ptr<T[]>(new T[height*width]); copy(m.dat.get(), m.dat.get()+width*height, dat.get()); return *this; } T * operator [] (int i) const { return dat.get() + i*width; } Mat & operator += (MCR x){ rep(i,height) rep(j,width) dat[i][j] += x[i][j]; return *this; } Mat & operator -= (MCR x){ rep(i,height) rep(j,width) dat[i][j] -= x[i][j]; return *this; } Mat & operator *= (MCR b){ Mat res(height, b.width); rep(i,height) rep(k,b.height) rep(j,b.width) { res[i][j] += (*this)[i][k]*b[k][j]; } return *this = res; } Mat operator + (MCR x) const { return Mat(*this) += x; } Mat operator - (MCR x) const { return Mat(*this) -= x; } Mat operator * (MCR x) const { return Mat(*this) *= x; } Mat exp(ll t) const { Mat e = *this, res = id(height); for(; t; e*=e, t>>=1) if(t&1) res *= e; return res; } Mat trans() const { Mat t(width, height); rep(i,width) rep(j,height) t[i][j] = dat[j][i]; return t; } static Mat id (int n) { Mat res(n,n); rep(i,n) res[i][i] = T(1); return res; } }; ll strMod(string const & s, ll M){ ll a = 0; rep(i, s.size()) a = (s[i] - '0' + a*10) % M; return a; } int const mod = 1000000007; typedef Mint<mod> mint; typedef Mat<mint> mat; mint fibonacci(ll n){ mat a(2,2); a[0][0] = mint(0); a[0][1] = mint(1); a[1][0] = mint(1); a[1][1] = mint(1); mat b(2,1); b[0][0] = mint(1); b[1][0] = mint(2); mat ans = a.exp(n) * b; return ans[0][0]; } int main(){ #ifdef LOCAL freopen("in","r",stdin); #endif int n; while(cin >> n){ mint ans(1); rep(i,n){ ll c; string d; cin >> c >> d; ll e = strMod(d,mod-1); ans *= fibonacci(c).exp(e); } cout << ans << endl; } }