結果

問題 No.917 Make One With GCD
ユーザー tkmst201tkmst201
提出日時 2019-10-25 23:42:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,124 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 183,228 KB
実行使用メモリ 9,556 KB
最終ジャッジ日時 2023-10-11 10:56:19
合計ジャッジ時間 7,327 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
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 WA -
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>;

// 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<1000000> > &bs) {
	if (k < 0) return 0;
	ll res = 0;
	
	while (k >= 0) {
		ll firc = 0, secc = 0, pos = -1;
		FOR(i, l, r) {
			if (bs[i][k] == 0) firc++;
			else {
				secc++;
				if (pos == -1) pos = i;
			}
		}
		res += ((1ll<<firc)-1) * ((1ll<<secc)-1);
		if (firc > 0 && secc > 0) {
			res += solve(l, pos, k - 1, bs);
			res += solve(pos, r, k - 1, bs);
			
			// printf("%d %lld %d %d\n", l, pos, r, k);
			break;
		}
		k--;
	}
	return res;
}


int main() {
	int N;
	int A[50];
	cin >> N;
	REP(i, N) cin >> A[i];
	
	vector<vector<pll> > pf(N);
	REP(i, N) pf[i] = primeFactorization(A[i]);
	
	set<ll> ss;
	REP(i, N) REP(j, pf[i].size()) ss.insert(pf[i][j].fi);
	
	map<ll, int> mm;
	for (ll u : ss) mm[u] = mm.size() - 1;
	
	vector<bitset<1000000> > bs(N);
	REP(i, N) REP(j, pf[i].size()) bs[i][mm[pf[i][j].fi]] = true;
	
	// 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