結果

問題 No.1253 雀見椪
ユーザー どららどらら
提出日時 2020-10-09 22:40:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 2,686 bytes
コンパイル時間 1,761 ms
コンパイル使用メモリ 176,108 KB
実行使用メモリ 34,396 KB
最終ジャッジ日時 2023-09-27 18:37:03
合計ジャッジ時間 3,864 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
34,244 KB
testcase_01 AC 33 ms
34,332 KB
testcase_02 AC 32 ms
34,204 KB
testcase_03 AC 36 ms
34,260 KB
testcase_04 AC 116 ms
34,268 KB
testcase_05 AC 117 ms
34,316 KB
testcase_06 AC 115 ms
34,136 KB
testcase_07 AC 119 ms
34,320 KB
testcase_08 AC 119 ms
34,140 KB
testcase_09 AC 115 ms
34,040 KB
testcase_10 AC 116 ms
34,392 KB
testcase_11 AC 116 ms
34,132 KB
testcase_12 AC 116 ms
34,212 KB
testcase_13 AC 116 ms
34,396 KB
testcase_14 AC 31 ms
34,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const long long mod = 1000000007;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  //mint(ll x = 0):x((x%mod+mod)%mod) {} // for minus
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(1);
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  
  //for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}
bool operator==(const mint& a, const mint& b){
  return a.x == b.x;
}
class modutils {
  vector<mint> fact, invfact;
public:
  modutils(int n = 2000005):fact(n+1),invfact(n+1) {
    fact[0] = 1;
    for(int i=1; i<=n; i++) fact[i] = fact[i-1] * i;
    invfact[n] = fact[n].inv();
    for(int i=n; i>=1; i--) invfact[i-1] = invfact[i] * i;
  }
  mint pow(mint x, ll n) {
    return x.pow(n);
  }
  mint comb(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[k] * invfact[n-k];
  }
  mint perm(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[n-k];
  }
  mint fac(ll n) {
    return fact[n];
  }
};
modutils mutil;

mint solve(ll N, mint PG, mint PC, mint PP) {
  mint ret(1);

  ret -= mutil.pow(PG+PC, N) - mutil.pow(PG, N) - mutil.pow(PC, N);
  ret -= mutil.pow(PG+PP, N) - mutil.pow(PG, N) - mutil.pow(PP, N);
  ret -= mutil.pow(PC+PP, N) - mutil.pow(PC, N) - mutil.pow(PP, N);

  return ret;
}

int main(){
  int T;
  cin >> T;

  rep(t,T){
    ll N;
    cin >> N;
    ll AG, BG, AC, BC, AP, BP;
    cin >> AG >> BG >> AC >> BC >> AP >> BP;
    mint PG = mint(AG) * (mint(BG).inv());
    mint PC = mint(AC) * (mint(BC).inv());
    mint PP = mint(AP) * (mint(BP).inv());
    cout << solve(N, PG, PC, PP) << endl;
  }
  
  return 0;
}

0