結果

問題 No.917 Make One With GCD
ユーザー tkmst201
提出日時 2019-10-26 15:39:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,265 bytes
コンパイル時間 2,462 ms
コンパイル使用メモリ 193,560 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-14 09:32:14
合計ジャッジ時間 3,617 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 10 WA * 22
権限があれば一括ダウンロードができます

ソースコード

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()) {
int sz = mm.size();
mm[pf[i][j].fi] = sz;
}
}
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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0