結果

問題 No.986 Present
ユーザー kyort0nkyort0n
提出日時 2020-02-11 15:28:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,723 bytes
コンパイル時間 2,739 ms
コンパイル使用メモリ 168,148 KB
実行使用メモリ 238,024 KB
最終ジャッジ日時 2023-07-24 12:44:37
合計ジャッジ時間 10,168 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 168 ms
237,796 KB
testcase_01 AC 168 ms
237,720 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 208 ms
237,720 KB
testcase_24 AC 300 ms
237,720 KB
testcase_25 AC 189 ms
237,776 KB
testcase_26 AC 307 ms
237,892 KB
testcase_27 AC 256 ms
237,948 KB
testcase_28 AC 169 ms
237,948 KB
testcase_29 AC 169 ms
237,716 KB
testcase_30 AC 169 ms
237,720 KB
testcase_31 AC 170 ms
237,808 KB
testcase_32 AC 169 ms
237,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//つぶあん つぶす
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const ll mod = 998244353;
ll inv[10000100];
ll FactorialInv[10000100];
ll Factorial[10000100];
ll beki(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    const int MAX = 10000002;
    Factorial[0] = 1;
    inv[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
    for(int i = 1; i <= MAX; i++) {
        inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}

ll N, M;
ll ans[3];

void ANSWER() {
    for(int i = 0; i < 3; i++) {
        if(i != 0) cout << " ";
        cout << ans[i];
    }
    cout << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    init_combination();
    cin >> N >> M;
    ans[0] = beki(2, N);
    ans[1] = 1;
    for(int i = 0; i < N; i++) {
        ans[1] *= beki(2, M - i) - 1;
        ans[1] %= mod;
        ans[1] *= beki(2, i);
        ans[1] %= mod;
    }
    for(int Empty = 0; Empty <= N + 1; Empty++) {
        ll tmp = combination(N + 1, Empty);
        tmp *= beki(N + 1 - Empty, M);
        tmp %= mod;
        //cerr << Empty << " " << tmp << endl;
        if(Empty & 1) ans[2] -= tmp;
        else ans[2] += tmp;
        //cerr << ans[2] << endl;
    }
    for(int Empty = 0; Empty <= N; Empty++) {
        ll tmp = combination(N, Empty);
        tmp *= beki(N - Empty, M);
        tmp %= mod;
        //cerr << Empty << " " << tmp << endl;
        if(Empty & 1) ans[2] -= tmp;
        else ans[2] += tmp;
        //cerr << ans[2] << endl;
    }
    ans[1] *= FactorialInv[N];
    ans[1] %= mod;
    ans[2] %= mod;
    ans[2] *= FactorialInv[N];
    ans[2] %= mod;
    ans[2] += mod;
    ans[2] %= mod;
    ANSWER();
    return 0;
}
0