結果

問題 No.1289 RNG and OR
ユーザー leaf_1415leaf_1415
提出日時 2020-11-13 23:08:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,935 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 75,392 KB
実行使用メモリ 11,512 KB
最終ジャッジ日時 2023-09-30 04:02:49
合計ジャッジ時間 1,780 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,520 KB
testcase_01 AC 2 ms
9,464 KB
testcase_02 AC 2 ms
9,452 KB
testcase_03 AC 2 ms
9,468 KB
testcase_04 AC 2 ms
9,500 KB
testcase_05 AC 3 ms
9,708 KB
testcase_06 AC 2 ms
9,464 KB
testcase_07 AC 2 ms
9,464 KB
testcase_08 AC 2 ms
9,516 KB
testcase_09 AC 2 ms
9,588 KB
testcase_10 AC 2 ms
9,464 KB
testcase_11 AC 2 ms
9,528 KB
testcase_12 AC 3 ms
9,604 KB
testcase_13 AC 3 ms
9,472 KB
testcase_14 AC 4 ms
9,636 KB
testcase_15 AC 6 ms
9,540 KB
testcase_16 AC 11 ms
9,648 KB
testcase_17 AC 19 ms
9,772 KB
testcase_18 AC 36 ms
10,108 KB
testcase_19 AC 73 ms
10,524 KB
testcase_20 AC 149 ms
11,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 998244353

using 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;
}
0