結果

問題 No.983 Convolution
ユーザー leaf_1415
提出日時 2020-02-11 13:45:41
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 871 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 57,864 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-10-01 07:25:20
合計ジャッジ時間 2,191 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#define llint long long

using namespace std;

llint n;
llint a[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)];
		}
	}
}

void moebius_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)];
		}
	}
}

llint gcd(llint a, llint b)
{
	if(b == 0) return a;
	return gcd(b, a%b);
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i], a[i] = max(a[i], 0LL);
	
	zeta_transform(a, 18);
	for(int i = 0; i < n; i++) a[i] *= a[i];
	moebius_transform(a, 18);
	
	llint ans = 0;
	for(int i = 0; i < n; i++) ans = gcd(ans, a[i]);
	if(ans == 0) ans = -1;
	cout << ans << endl;
	
	return 0;
}
0