結果

問題 No.1253 雀見椪
ユーザー fastmathfastmath
提出日時 2020-10-09 23:40:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 3,377 bytes
コンパイル時間 2,044 ms
コンパイル使用メモリ 203,360 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 20:00:22
合計ジャッジ時間 3,389 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 34 ms
4,380 KB
testcase_05 AC 34 ms
4,376 KB
testcase_06 AC 35 ms
4,376 KB
testcase_07 AC 34 ms
4,380 KB
testcase_08 AC 34 ms
4,376 KB
testcase_09 AC 35 ms
4,376 KB
testcase_10 AC 34 ms
4,376 KB
testcase_11 AC 35 ms
4,380 KB
testcase_12 AC 34 ms
4,380 KB
testcase_13 AC 35 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';


const int MOD = 1e9+7, N = 2007;
//need define int long long
int mod(int n) {
    n %= MOD;
    if (n < 0) return n + MOD;
    else return n;
}   
int fp(int a, int p) {
    int ans = 1, c = a;
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) ans = mod(ans * c);
        c = mod(c * c);
    }   
    return ans;
}   
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }

struct M {
ll x;
M (int x_) {
    x = mod(x_);
}   
M () {
    x = 0;
}
M operator + (M y) {
    int ans = x + y.x;
    if (ans >= MOD)
        ans -= MOD;
    return M(ans);
}
M operator - (M y) {
    int ans = x - y.x;
    if (ans < 0)
        ans += MOD;
    return M(ans);            
}   
M operator * (M y) {
    return M(x * y.x % MOD);   
}   
M operator / (M y) {
    return M(x * fp(y.x, MOD - 2) % MOD);
}   
M operator + (int y) {
    return (*this) + M(y);
}
M operator - (int y) {
    return (*this) - M(y);
}   
M operator * (int y) {
    return (*this) * M(y);
}   
M operator / (int y) {
    return (*this) / M(y);
}   
M operator ^ (int p) {
    return M(fp(x, p));
}   
void operator += (M y) {
    *this = *this + y;
}   
void operator -= (M y) {
    *this = *this - y;
}   
void operator *= (M y) {
    *this = *this * y;
}
void operator /= (M y) {
    *this = *this / y;
}   
void operator += (int y) {
    *this = *this + y;
}   
void operator -= (int y) {
    *this = *this - y;
}   
void operator *= (int y) {
    *this = *this * y;
}
void operator /= (int y) {
    *this = *this / y;
}   
void operator ^= (int p) {
    *this = *this ^ p;
}
};  

M f[N], inv[N];
void prec() {
    f[0] = M(1);
    for (int i = 1; i < N; ++i)
        f[i] = f[i - 1] * M(i);
    inv[N - 1] = f[N - 1] ^ (MOD - 2);
    for (int i = N - 2; i >= 0; --i)
        inv[i] = inv[i + 1] * M(i + 1);
}
M C(int n, int k) {
    if (n < k)
        return M(0);
    else
        return f[n] * inv[k] * inv[n - k];
}   


signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20); 
    #endif
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;

        auto read = [&] () {
            int a, b;
            cin >> a >> b;
            return M(a)/b;
        };

        auto a = read();
        auto b = read();
        auto c = read();

        vector <M> p = {a, b, c};

        auto get = [&] (M a, M b) {
            M ans(0);
            for (int i = 0; i <= n; ++i) {
                ans += (a^i) * (b ^ (n - i));
            }   
            return ans;
        };  

        /*
        cout << get(p[0], p[1]).x << endl;
        cout << (M(4)/27).x << endl;
        exit(0);
        */

        M ans(1);
        for (int i = 0; i < 3; ++i) {
            auto nt = M(1) - p[i];
            ans -= nt ^ n;
        }   
        for (int i = 0; i < 3; ++i) {
            ans += (p[i] ^ n) * 2;
        }   
        cout << ans.x << endl;
    }   
}
0