結果

問題 No.983 Convolution
ユーザー EnderedEndered
提出日時 2020-02-11 15:02:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,220 bytes
コンパイル時間 1,888 ms
コンパイル使用メモリ 184,052 KB
実行使用メモリ 13,352 KB
最終ジャッジ日時 2024-04-08 15:15:39
合計ジャッジ時間 7,372 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,352 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 274 ms
6,548 KB
testcase_04 AC 907 ms
6,548 KB
testcase_05 AC 568 ms
6,548 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
}

map<ll, ll> prime_melt(ll x){
    map<ll, ll> res;
    for(int i=2;i*i<=x;++i){
        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;
    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);

    bool is_all = [](vector<ll> line){
        int n = line.size();
        vector<bool> check(n, false);
        rep(i, n){
            check[i] = line[i] == -1;
        }
        per(i, n){
            if(!check[i])return false;
            rep(j, 31){
                if(bit(j)&i){
                    check[bit(j)^i] = true;
                }
            }
        }
        return true;
    }(line);
    if(is_all){
        cout << -1 << endl;
        return 0;
    }
    if(cnt<=1){
        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