結果

問題 No.983 Convolution
ユーザー nikutto_nikutto_
提出日時 2020-02-12 19:03:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,231 bytes
コンパイル時間 1,948 ms
コンパイル使用メモリ 170,236 KB
実行使用メモリ 28,116 KB
最終ジャッジ日時 2024-04-14 22:55:07
合計ジャッジ時間 7,910 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
27,988 KB
testcase_01 AC 101 ms
27,860 KB
testcase_02 AC 102 ms
27,992 KB
testcase_03 AC 143 ms
27,864 KB
testcase_04 AC 144 ms
27,864 KB
testcase_05 AC 134 ms
27,860 KB
testcase_06 AC 152 ms
27,856 KB
testcase_07 AC 142 ms
27,860 KB
testcase_08 AC 111 ms
27,860 KB
testcase_09 WA -
testcase_10 AC 108 ms
27,860 KB
testcase_11 AC 115 ms
27,860 KB
testcase_12 AC 142 ms
27,988 KB
testcase_13 AC 122 ms
27,860 KB
testcase_14 AC 122 ms
27,864 KB
testcase_15 WA -
testcase_16 AC 125 ms
27,860 KB
testcase_17 WA -
testcase_18 AC 111 ms
27,856 KB
testcase_19 AC 130 ms
27,864 KB
testcase_20 AC 150 ms
27,864 KB
testcase_21 AC 153 ms
27,856 KB
testcase_22 AC 111 ms
27,860 KB
testcase_23 AC 123 ms
27,984 KB
testcase_24 AC 108 ms
27,860 KB
testcase_25 AC 108 ms
27,856 KB
testcase_26 AC 116 ms
27,984 KB
testcase_27 AC 113 ms
27,860 KB
testcase_28 AC 142 ms
27,864 KB
testcase_29 AC 180 ms
27,860 KB
testcase_30 AC 143 ms
27,860 KB
testcase_31 AC 124 ms
27,860 KB
testcase_32 AC 146 ms
27,860 KB
testcase_33 AC 102 ms
27,860 KB
testcase_34 AC 101 ms
27,860 KB
testcase_35 AC 107 ms
27,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll=__int128;
ll mygcd(ll a,ll b){
    return b==0 ? a : mygcd(b,a%b);
}

const int LOG_N=18;
const int MAX_N=1<<LOG_N;
ll B[MAX_N];

ll cross(ll a,ll b){
   return min(a,b)==-1LL ? -1LL : a*b;
}
void add(ll& lhs,ll v){
    if(min(lhs,v)==-1) lhs=-1;
    else lhs+=v;
}
void solve(int step,vector<ll> A,int mask){
    if(A.size()==1){
        add(B[mask],cross(A[0],A[0]));
        return;
    }
    vector<ll> odd(A.size()/2);
    for(int i=1;i<A.size();i+=2) odd[i/2]=A[i];
    solve(step+1,odd,mask+(1<<step));

    vector<ll> even(A.size()/2);
    for(int i=0;i<A.size();i++) add(even[i/2],A[i]);
    solve(step+1,even,mask);
}

string to_str(ll v){
    string res;
    while(v){
        res+=('0'+v%10);
        v/=10;
    }
    reverse(res.begin(),res.end());
    return res;
}
int main(){
    int n;
    cin>>n;
    vector<ll> A(MAX_N);
    for(int i=0;i<n;i++){
        int tmp;
        cin>>tmp;
        A[i]=tmp;
    }

    solve(0,A,0);

    for(int i=0;i<MAX_N;i++){
        if(B[i]==-1) B[i]=0;
    }

    ll ans=0;
    for(int i=0;i<MAX_N;i++){
        ans=mygcd(ans,B[i]);
    }
    if(ans==0) cout<<-1<<endl;
    else cout<<to_str(ans)<<endl;
    
    return 0;
}
0