結果
問題 | No.1289 RNG and OR |
ユーザー |
![]() |
提出日時 | 2020-11-13 23:08:58 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 165 ms / 2,000 ms |
コード長 | 1,935 bytes |
コンパイル時間 | 1,072 ms |
コンパイル使用メモリ | 79,672 KB |
実行使用メモリ | 11,520 KB |
最終ジャッジ日時 | 2024-07-22 22:01:37 |
合計ジャッジ時間 | 1,943 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include <iostream>#include <cstdio>#include <cmath>#include <ctime>#include <cstdlib>#include <cassert>#include <vector>#include <list>#include <stack>#include <queue>#include <deque>#include <map>#include <set>#include <bitset>#include <string>#include <algorithm>#include <utility>#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)#define chmin(x, y) (x) = min((x), (y))#define chmax(x, y) (x) = max((x), (y))#define all(x) (x).begin(),(x).end()#define inf 1e18#define mod 998244353using namespace std;typedef long long llint;typedef pair<llint, llint> P;llint n;llint a[1<<18];llint p[1<<18];llint A[1<<18], B[1<<18];void zeta_transform(llint a[], int n){int S = 1<<n;for(int i = 0; i < n; i++){for(int j = 0; j < S; j++){if(!(j&(1<<i))) (a[j] += a[j^(1<<i)])%=mod;}}}void zeta_transform2(llint a[], int n){int S = 1<<n;for(int i = 0; i < n; i++){for(int j = 0; j < S; j++){if((j&(1<<i))) (a[j] += a[j^(1<<i)])%=mod;}}}void moebius_transform2(llint a[], int n){int S = 1<<n;for(int i = 0; i < n; i++){for(int j = 0; j < S; j++){if((j&(1<<i))) (a[j] += mod-a[j^(1<<i)]) %= mod;}}}llint modpow(llint a, llint n){if(n == 0) return 1;if(n % 2){return ((a%mod) * (modpow(a, n-1)%mod)) % mod;}else{return modpow((a*a)%mod, n/2) % mod;}}int main(void){ios::sync_with_stdio(0);cin.tie(0);cin >> n;llint N = 1<<n;llint sum = 0;rep(i, 0, N-1) cin >> a[i], sum += a[i], sum %= mod;sum = modpow(sum, mod-2);rep(i, 0, N-1) p[i] = a[i] * sum % mod;rep(i, 0, N-1) A[i] = B[i] = p[i];zeta_transform(A, n), zeta_transform2(B, n);llint ans = 0;rep(i, 0, N-1){llint pop = 0;rep(j, 0, n-1) if(i & (1<<j)) pop++;llint b = (B[(N-1)-i]+mod-1) % mod;b = modpow(b, mod-2);if(pop % 2 == 0) ans += b, ans %= mod;else ans += mod - b, ans %= mod;}cout << ans << endl;return 0;}