結果

問題 No.983 Convolution
ユーザー koi_kotyakoi_kotya
提出日時 2020-02-11 15:00:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,852 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 184,540 KB
実行使用メモリ 18,936 KB
最終ジャッジ日時 2024-04-08 15:15:05
合計ジャッジ時間 8,035 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
18,936 KB
testcase_01 AC 9 ms
18,936 KB
testcase_02 AC 8 ms
18,936 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 91 ms
18,936 KB
testcase_14 AC 85 ms
18,936 KB
testcase_15 AC 119 ms
18,936 KB
testcase_16 AC 87 ms
18,936 KB
testcase_17 AC 127 ms
18,936 KB
testcase_18 AC 42 ms
18,936 KB
testcase_19 AC 128 ms
18,936 KB
testcase_20 AC 164 ms
18,936 KB
testcase_21 AC 524 ms
18,936 KB
testcase_22 AC 38 ms
18,936 KB
testcase_23 AC 34 ms
18,936 KB
testcase_24 AC 15 ms
18,936 KB
testcase_25 AC 13 ms
18,936 KB
testcase_26 AC 24 ms
18,936 KB
testcase_27 AC 20 ms
18,936 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 9 ms
18,936 KB
testcase_34 AC 8 ms
18,936 KB
testcase_35 AC 9 ms
18,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

ll gcd(ll a,ll b) {
    while (b) {
        a %= b;
        swap(a,b);
    }
    return a;
}


int const MAX_N = 1000;
vector<ll> prime;
vector<bool> is_prime(MAX_N,true);
void Eratosthenes() {
    is_prime[0] = is_prime[1] = false;
    for (ll i = 2;i*i < MAX_N;++i) if (is_prime[i]) for (ll j = 2*i;j < MAX_N;j += i) is_prime[j] = false;
    for (ll i = 0;i < MAX_N;++i) if (is_prime[i]) prime.push_back(i);
}

int main() {
    Eratosthenes();
    int n;cin >> n;
    vector<ll> a(1000000,0),c;
    for (int i = 0;i < n;++i) cin >> a[i];
    c = a;
    for (int i = 0;i < 19;++i) for (int j = 0;j < n;++j) if (!(j&(1<<i)) && c[j] > -1) {
        if (c[i|(1<<i)] > -1) c[j] += c[i|(1<<i)];
        else c[j] = -1;
    }
    map<ll,int> mp;
    for (int i = 0;i < n;++i) if (a[i] > -1) {
        map<ll,int> mp2;
        mp2[1]++;
        for (ll j : prime) {
            if (j*j > a[i]) break;
            while (a[i]%j == 0) mp2[j]++,a[i] /= j;
        }
        if (a[i] > 1) mp2[a[i]]++;
        for (ll j : prime) {
            if (j*j > c[i]) break;
            while (c[i]%j == 0) mp2[j]++,c[i] /= j;
        }
        if (c[i] > 1) mp2[c[i]]++;
        if (mp.size() == 0) mp = mp2;
        else for (auto& p : mp) p.second = min(p.second,mp2[p.first]);
    }
    ll ans = 1;
    for (auto p : mp) for (int i = 0;i < p.second;++i) ans *= p.first;
    cout << (mp.size() ? ans : -1) << endl;
}
0