結果

問題 No.983 Convolution
ユーザー EnderedEndered
提出日時 2020-02-11 15:08:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,162 ms / 2,000 ms
コード長 3,061 bytes
コンパイル時間 1,890 ms
コンパイル使用メモリ 180,868 KB
実行使用メモリ 5,956 KB
最終ジャッジ日時 2023-07-24 12:36:17
合計ジャッジ時間 9,008 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 107 ms
5,188 KB
testcase_04 AC 205 ms
4,664 KB
testcase_05 AC 136 ms
4,384 KB
testcase_06 AC 1,162 ms
5,340 KB
testcase_07 AC 82 ms
5,532 KB
testcase_08 AC 18 ms
4,384 KB
testcase_09 AC 16 ms
4,384 KB
testcase_10 AC 21 ms
4,380 KB
testcase_11 AC 58 ms
4,380 KB
testcase_12 AC 79 ms
5,880 KB
testcase_13 AC 220 ms
4,380 KB
testcase_14 AC 184 ms
4,384 KB
testcase_15 AC 207 ms
5,160 KB
testcase_16 AC 162 ms
4,880 KB
testcase_17 AC 229 ms
5,344 KB
testcase_18 AC 65 ms
4,380 KB
testcase_19 AC 244 ms
4,380 KB
testcase_20 AC 296 ms
5,956 KB
testcase_21 AC 555 ms
5,164 KB
testcase_22 AC 60 ms
4,380 KB
testcase_23 AC 22 ms
5,176 KB
testcase_24 AC 7 ms
4,380 KB
testcase_25 AC 5 ms
4,384 KB
testcase_26 AC 14 ms
4,380 KB
testcase_27 AC 12 ms
4,380 KB
testcase_28 AC 326 ms
4,680 KB
testcase_29 AC 453 ms
5,664 KB
testcase_30 AC 153 ms
4,384 KB
testcase_31 AC 61 ms
4,380 KB
testcase_32 AC 357 ms
4,616 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define OUTPUT(x) (output(x), output("\n"))
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
        if(b&1)res = res * x % MOD;
        x = x * x % MOD;
        b>>=1;
    }
    return res;
}

ll modinv(ll x){
    return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
}
void outendl(){
    was_output = false;
    cout << endl;
}

ll norpow(ll x, ll b){
    ll res = 1;
    while(b){
        if(b&1)res = res * x;
        x = x * x;
        b>>=1;
    }
    return res;
}

vector<ll> primes;
void set_primes(){
    vector<bool> flag(40005, true);
    for(int i=2;i<flag.size();++i){
        if(flag[i]){
            primes.push_back(i);
            for(int j=i*2;j<flag.size();j+=i){
                flag[j] = false;
            }
        }
    }
}

map<ll, ll> prime_melt(ll x){
    map<ll, ll> res;
    foreach(i, primes){
        if(i*i>x)break;
        int cnt = 0;
        while(x%i==0){
            ++cnt;
            x /= i;
        }
        if(cnt){
            res[i] = cnt;
        }
    }
    if(x!=1){
        res[x] = 1;
    }
    return res;
}

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

int main(){
    int n;
    cin >> n;
    set_primes();
    vector<ll> line(n);
    foreach(i, line){
        cin >> i;
    }
    int cnt = [](vector<ll> line){
        int res = 0;
        foreach(i, line){
            if(i!=-1)++res;
        }
        return res;
    }(line);

    if(cnt==0){
        cout << -1 << endl;
        return 0;
    }
    map<ll, ll> m;
    bool flag = false;
    foreach(i, line){
        if(i==-1)continue;
        map<ll, ll> res = prime_melt(i);
        map<ll, ll> nm;
        if(flag){
            foreach(j, res){
                if(m.count(j.first)){
                    nm[j.first] = min(m[j.first], j.second);
                }
            }
        }else{
            nm = res;
        }
        flag = true;
        m = nm;
    }

    ll res = 1;
    foreach(i, m){
        res *= norpow(i.first, i.second*2);
    }
    cout << res << endl;
    return 0;
}
0