結果

問題 No.1127 変形パスカルの三角形
ユーザー fastmathfastmath
提出日時 2020-08-02 04:29:46
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 1,500 ms
コード長 2,779 bytes
コンパイル時間 7,871 ms
コンパイル使用メモリ 132,552 KB
実行使用メモリ 6,580 KB
最終ジャッジ日時 2023-09-24 12:38:18
合計ジャッジ時間 11,959 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,500 KB
testcase_01 AC 11 ms
6,524 KB
testcase_02 AC 9 ms
6,552 KB
testcase_03 AC 8 ms
6,516 KB
testcase_04 AC 6 ms
6,516 KB
testcase_05 AC 8 ms
6,544 KB
testcase_06 AC 11 ms
6,540 KB
testcase_07 AC 8 ms
6,520 KB
testcase_08 AC 7 ms
6,576 KB
testcase_09 AC 10 ms
6,544 KB
testcase_10 AC 11 ms
6,556 KB
testcase_11 AC 9 ms
6,556 KB
testcase_12 AC 9 ms
6,580 KB
testcase_13 AC 9 ms
6,504 KB
testcase_14 AC 8 ms
6,496 KB
testcase_15 AC 7 ms
6,560 KB
testcase_16 AC 9 ms
6,536 KB
testcase_17 AC 8 ms
6,548 KB
testcase_18 AC 9 ms
6,524 KB
testcase_19 AC 10 ms
6,572 KB
testcase_20 AC 10 ms
6,540 KB
testcase_21 AC 9 ms
6,544 KB
testcase_22 AC 7 ms
6,580 KB
testcase_23 AC 10 ms
6,544 KB
testcase_24 AC 8 ms
6,536 KB
testcase_25 AC 9 ms
6,488 KB
testcase_26 AC 9 ms
6,552 KB
testcase_27 AC 10 ms
6,500 KB
testcase_28 AC 9 ms
6,552 KB
testcase_29 AC 7 ms
6,556 KB
testcase_30 AC 7 ms
6,536 KB
testcase_31 AC 10 ms
6,536 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 = 1000 * 1000 * 1000 + 7, N = 2e5+7;
//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 () {}
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);
    #endif
    
    int a, b, n, k;
    cin >> a >> b >> n >> k;

    prec();
    a = mod(a); b = mod(b);
    cout << (C(n - 1, k - 1) * a + C(n - 1, k - 2) * b).x << endl;

    M ans = M(0);
    for (int k = 1; k <= n + 1; ++k) {
        M t =         C(n - 1, k - 1) * a + C(n - 1, k - 2) * b;
        ans += t * t;
    }   
    cout << ans.x << endl;
}
0