結果
| 問題 |
No.2206 Popcount Sum 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-14 12:56:56 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,783 bytes |
| コンパイル時間 | 2,444 ms |
| コンパイル使用メモリ | 116,672 KB |
| 最終ジャッジ日時 | 2025-02-11 11:07:43 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 WA * 13 TLE * 4 |
ソースコード
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;
bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
#define MOD 998244353
int expit(LL b, int e) {
LL r=1;
while(e) {
if (e&1) { r*=b; r%=MOD; }
b*=b; b%=MOD;
e>>=1;
}
return r;
}
int bb[200004];
int ss[200004];
int ft[200004];
int ift[200004];
#define BB 500
int xx[401][200004]; // (500+200000)*400/2
int main() {
int n, i, m, k, nn;
int inv2 = expit(2, MOD-2);
LL r, t, s;
bb[0]=1;
ft[0]=ift[0]=1;
for (i=1; i<=200000; i++) {
bb[i]=(bb[i-1]*2)%MOD;
r=ft[i-1]; r*=i; r%=MOD;
ft[i]=r;
ift[i]=expit(r, MOD-2);
}
ss[0]=0; for (i=1; i<=200000; i++) ss[i]=(ss[i-1]+bb[i-1])%MOD;
for (n=BB; n<200000; n+=BB) {
k = n/BB-1;
s=0; for (m=0; m<=n; m++) {
t=ft[n]; t*=ift[m]; t%=MOD; t*=ift[n-m]; t%=MOD;
s+=t; s%=MOD;
xx[k][m]=s;
}
}
int tc; scanf("%d", &tc); while(tc) { tc--;
scanf("%d %d", &n, &m);
// printf("%d:%d\n", n, ss[n]);
n--; m--;
k = (n+BB-1)/BB-1;
nn = (k+1)*BB;
r = xx[k][m];
while(nn>n) {
nn--;
// move nn-> nn-1
t=ft[nn]; t*=ift[m]; t%=MOD; t*=ift[nn-m]; t%=MOD;
t+=r; t%=MOD; t*=inv2; t%=MOD;
r=t;
}
// c(n-1, m-1)+...C(n-1, 0)
// r=ft[n-1]; r*=ift[m-1]; r%=MOD; r*=ift[n-m]; r%=MOD;
r*=ss[n+1]; r%=MOD;
printf("%lld\n", r);
}
return 0;
}