結果
| 問題 | No.3394 Big Binom |
| コンテスト | |
| ユーザー |
Cafe1942
|
| 提出日時 | 2025-11-25 20:23:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,648 bytes |
| 記録 | |
| コンパイル時間 | 1,119 ms |
| コンパイル使用メモリ | 121,240 KB |
| 実行使用メモリ | 10,920 KB |
| 最終ジャッジ日時 | 2025-11-30 23:30:12 |
| 合計ジャッジ時間 | 11,389 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 13 TLE * 1 -- * 7 |
ソースコード
#include <iostream>
#include <iomanip>//小数点出力用
//cout << fixed << setprecision(10) << ans;
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using ll = unsigned long long;
using namespace std;
#define modPHash (ll)((1LL<<61)-1)
#define modP (ll)998244353
bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); }
int clk4(int num) { return (num - 2) * (num % 2); }
void yn(bool tf) { cout << (tf ? "YES\n" : "NO\n"); }
unordered_map<int, int>init_fact;
ll factorial(int N) {
int Q = N / 100'000'000;
int R = N % 100'000'000;
ll res = init_fact[Q * 100'000'000];
for (int i = 1;i <= R;i++) {
res *= (ll)(i + Q * 100'000'000);
res %= 998244353;
}
return res;
}
ll modpow(ll b, ll e, ll q) {
int i;
ll bp = b % q;
ll tmp = 1;
for (i = 0; tmp <= e; i++) {
tmp *= 2;
}
tmp /= 2;
i--;
ll ans = 1;
for (; i >= 0; i--) {
ans = (ll)ans * (ll)ans;
ans %= q;
if ((e >> i) % 2 == 1) {
ans *= (ll)bp;
}
ans %= q;
tmp /= (ll)2;
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
init_fact[0] = 1;
init_fact[100'000'000] = 808258749;
init_fact[200'000'000] = 117153405;
init_fact[300'000'000] = 761699708;
init_fact[400'000'000] = 573994984;
init_fact[500'000'000] = 62402409;
init_fact[600'000'000] = 511621808;
init_fact[700'000'000] = 242726978;
init_fact[800'000'000] = 887890124;
init_fact[900'000'000] = 875880304;
int N;
cin >> N;
int K;
cin >> K;
if (!(1 <= N && N <= 1'000'000'000 && 0 <= K && K <= N)) {//制約違反検出
int tmptmp1 = 1;
int tmptmp0 = 0;
N = tmptmp1 / tmptmp0;//Run Time Errorさせる
return 0;
}
if (N >= 998244353) {
if (max(K, N - K) >= 998244353) {
ll ans = 1;
for (int i = 0;i < K;i++) {
ans *= (ll)(N - i);
ans %= 998244353;
}
for (int i = 1;i <= min(K, N - K);i++) {
ans *= modpow(i, 998244353 - 2, 998244353);
ans %= 998244353;
}
cout << ans;
}
else {
cout << 0;
}
}
else {
ll top = factorial(N);
ll bot = factorial(N - K) * factorial(K);
bot %= 998244353;
top *= modpow(bot, 998244353 - 2, 998244353);
top %= 998244353;
cout << top;
}
return 0;
}
Cafe1942