結果
| 問題 |
No.986 Present
|
| コンテスト | |
| ユーザー |
kyort0n
|
| 提出日時 | 2020-02-11 15:28:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,723 bytes |
| コンパイル時間 | 1,634 ms |
| コンパイル使用メモリ | 171,396 KB |
| 実行使用メモリ | 238,028 KB |
| 最終ジャッジ日時 | 2024-10-01 07:57:42 |
| 合計ジャッジ時間 | 9,483 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 10 WA * 20 |
ソースコード
//つぶあん つぶす
#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;
}
kyort0n