結果
問題 | No.917 Make One With GCD |
ユーザー |
![]() |
提出日時 | 2019-10-25 23:12:49 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,003 bytes |
コンパイル時間 | 2,185 ms |
コンパイル使用メモリ | 190,812 KB |
実行使用メモリ | 10,448 KB |
最終ジャッジ日時 | 2024-09-13 08:27:13 |
合計ジャッジ時間 | 7,823 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 RE * 3 |
other | AC * 3 RE * 29 |
ソースコード
#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 secondtemplate<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[res.size() - 1].second++;}}if (n > 1) res.push_back(pll(n, 1));return res;}int N;int A[50];// [l, r)ll solve(int l, int r, int k, vector<bitset<1000000> > &bs) {if (k < 0) return 0;ll res = 0;ll firc = 0, secc = 0, pos = -1;FOR(i, l, r) {if (!bs[i][k]) 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);}else {res += solve(l, r, k - 1, bs);}return res;}int main() {cin >> N;REP(i, N) cin >> A[i];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;int onc = 0;REP(i, N) if (A[i] == 1) onc++;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();});ll ans = solve(0, N, ss.size() - 1, bs);ans += (1ll<<onc)-1;cout << ans << endl;return 0;}