結果

問題 No.917 Make One With GCD
ユーザー tkmst201tkmst201
提出日時 2019-10-26 15:39:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,249 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 188,744 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 10:37:20
合計ジャッジ時間 6,947 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 1 ms
4,348 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

using pll = pair<ll, ll>;
const int SIZE = 2000;

// nを素因数分解する (素因数, 個数)が戻り値
vector<pll> primeFactorization(ll n) {
	vector<pll> res;
	
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0) res.push_back(pll(i, 0));
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n > 1) res.emplace_back(n, 1);
	
	return res;
}

// [l, r)
ll solve(int l, int r, int k, vector<bitset<SIZE> > &bs) {
	if (k < 0) return 0;
	ll res = 0;
	
	while (k >= 0) {
		int firc = 0, secc = 0, pos = -1;
		FOR(i, l, r) {
			if (bs[i][k] == 0) firc++;
			else {
				secc++;
				if (pos == -1) pos = i;
			}
		}
		if (firc > 0 && secc > 0) {
			res += ((1ll<<firc)-1) * ((1ll<<secc)-1);
			res += solve(l, pos, k - 1, bs);
			res += solve(pos, r, k - 1, bs);
			
			// printf("%d %d %d %d\n", l, pos, r, k);
			break;
		}
		k--;
	}
	return res;
}


int main() {
	int N; cin >> N;
	vector<int> A(N);
	REP(i, N) cin >> A[i];
	
	vector<vector<pll> > pf(N);
	REP(i, N) pf[i] = primeFactorization(A[i]);
	
	map<ll, int> mm;
	REP(i, N) REP(j, pf[i].size()) {
		if (mm.find(pf[i][j].fi) == mm.end()) mm[pf[i][j].fi] = (int)mm.size() - 1;
	}
	
	vector<bitset<SIZE> > bs(N, bitset<SIZE>(0));
	REP(i, N) REP(j, pf[i].size()) {
		assert(mm[pf[i][j].fi] < SIZE);
		assert(mm[pf[i][j].fi] >= 0);
		bs[i].set(mm[pf[i][j].fi]);
		// cout << mm[pf[i][j].fi] << endl;
	}
	
	sort(ALL(bs), [&](auto x, auto y) {
		return x.to_string() < y.to_string();
	});
	
	// REP(i, N) cout << bs[i] << endl;
	
	int onc = 0;
	REP(i, N) if (A[i] == 1) onc++;
	
	ll ans = solve(0, N, mm.size(), bs);
	ans += (1ll<<onc)-1;
	cout << ans << endl;
	return 0;
}
0