結果

問題 No.983 Convolution
ユーザー chocopuuchocopuu
提出日時 2020-02-11 15:35:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,021 bytes
コンパイル時間 1,920 ms
コンパイル使用メモリ 183,032 KB
実行使用メモリ 26,492 KB
最終ジャッジ日時 2024-04-08 15:28:28
合計ジャッジ時間 13,194 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
26,492 KB
testcase_01 AC 8 ms
19,688 KB
testcase_02 AC 8 ms
19,688 KB
testcase_03 AC 52 ms
19,688 KB
testcase_04 AC 74 ms
19,688 KB
testcase_05 AC 43 ms
19,688 KB
testcase_06 AC 67 ms
19,688 KB
testcase_07 AC 51 ms
19,688 KB
testcase_08 AC 16 ms
19,688 KB
testcase_09 WA -
testcase_10 AC 18 ms
19,688 KB
testcase_11 AC 52 ms
19,688 KB
testcase_12 AC 52 ms
19,688 KB
testcase_13 AC 150 ms
19,688 KB
testcase_14 AC 37 ms
19,688 KB
testcase_15 WA -
testcase_16 AC 35 ms
19,688 KB
testcase_17 WA -
testcase_18 AC 20 ms
19,688 KB
testcase_19 AC 50 ms
19,688 KB
testcase_20 AC 60 ms
19,688 KB
testcase_21 AC 312 ms
19,688 KB
testcase_22 AC 22 ms
19,688 KB
testcase_23 AC 32 ms
19,688 KB
testcase_24 AC 13 ms
19,688 KB
testcase_25 AC 12 ms
19,688 KB
testcase_26 AC 24 ms
19,688 KB
testcase_27 AC 19 ms
19,688 KB
testcase_28 AC 1,897 ms
19,688 KB
testcase_29 TLE -
testcase_30 AC 666 ms
19,688 KB
testcase_31 AC 380 ms
19,688 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
template<class T>inline void out(T t){cout<<t<<"\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout<<t<<" ";out(ts...);}
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;}
constexpr long long INF = 1e18;

#define ull unsigned long long

ull gcd(ull x,ull y)
{
	if(x==0) return y;
	return gcd(y%x,x);
}
int lcm(int x, int y)
{
	return (x * y / gcd(x, y));
}

vector<pair<long long, long long> > prime_factorize(long long n) {
	vector<pair<long long, long long> > res;
	for (long long p = 2; p * p <= n; ++p) {
		if (n % p != 0) continue;
		int num = 0;
		while (n % p == 0) { ++num; n /= p; }
		res.push_back(make_pair(p, num));
	}
	if (n != 1) res.push_back(make_pair(n, 1));
	return res;
}

long long mod_pow(long long x, long long n) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}


signed main(){
	int N;
	cin >> N;
	vector<int>a(1ll << 20);
	vector<int>ok(1ll << 20);
	REP(i,N){
		cin >> a[i];
		if(a[i] == -1)ok[i] = 1;
	}
	REP(k,20){
		REP(s,N){
			if(!((s>>k)&1)){
				if(ok[s^(1ll<<k)])ok[s]=1;
				else if(a[s] == -1)continue;
				else a[s]+=a[s^(1ll<<k)];
			}
		}
	}
	int flg = 0;
	map<int,int>mp;
	REP(i,N){
		if(ok[i])continue;
		map<int,int>nex;
		auto p = prime_factorize(a[i]);
		if(flg==0){
			for(auto e:p)mp[e.first]=e.second*2;
			flg=1;
			continue;
		}
		for(auto e:p){
			if(mp.count(e.first)){
				nex[e.first] = min(e.second*2,mp[e.first]);
			}
		}
		mp = nex;
	}
	if(flg==0){
		cout << -1 << endl;
		return 0;
	}
	ull g = 1;
	for(auto e:mp){
		g *= mod_pow(e.first,e.second);
	}
	out(g);
}
0