結果
問題 | No.1253 雀見椪 |
ユーザー | umezo |
提出日時 | 2020-10-09 23:17:45 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 72 ms / 2,000 ms |
コード長 | 2,225 bytes |
コンパイル時間 | 2,028 ms |
コンパイル使用メモリ | 200,864 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-09-27 19:42:02 |
合計ジャッジ時間 | 3,424 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 7 ms
4,376 KB |
testcase_04 | AC | 67 ms
4,376 KB |
testcase_05 | AC | 67 ms
4,380 KB |
testcase_06 | AC | 66 ms
4,380 KB |
testcase_07 | AC | 67 ms
4,376 KB |
testcase_08 | AC | 68 ms
4,380 KB |
testcase_09 | AC | 66 ms
4,380 KB |
testcase_10 | AC | 69 ms
4,376 KB |
testcase_11 | AC | 70 ms
4,376 KB |
testcase_12 | AC | 72 ms
4,380 KB |
testcase_13 | AC | 69 ms
4,376 KB |
testcase_14 | AC | 2 ms
4,376 KB |
ソースコード
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; template< int mod > struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % 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 = (int) (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, t; while(b > 0) { 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; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); } static int get_mod() { return mod; } }; using mint = ModInt< 1000000007 >; int main() { int t; cin>>t; while(t--){ ll n; cin>>n; mint ag,bg,ac,bc,ap,bp; cin>>ag>>bg>>ac>>bc>>ap>>bp; ag=ag*(bg.inverse()); ac=ac*(bc.inverse()); ap=ap*(bp.inverse()); mint x,y,z; x=ag+ac; y=ac+ap; z=ap+ag; mint ans=(mint)1+(mint)2*(ag.pow(n)+ac.pow(n)+ap.pow(n))-x.pow(n)-y.pow(n)-z.pow(n); cout<<ans<<endl; } return 0; }