結果

問題 No.983 Convolution
ユーザー nikutto_nikutto_
提出日時 2020-02-12 19:07:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,171 bytes
コンパイル時間 6,911 ms
コンパイル使用メモリ 380,772 KB
実行使用メモリ 52,656 KB
最終ジャッジ日時 2024-04-14 22:55:48
合計ジャッジ時間 18,969 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 273 ms
52,372 KB
testcase_01 AC 270 ms
52,440 KB
testcase_02 AC 268 ms
52,476 KB
testcase_03 AC 300 ms
52,388 KB
testcase_04 AC 309 ms
52,444 KB
testcase_05 AC 294 ms
52,376 KB
testcase_06 AC 309 ms
52,420 KB
testcase_07 AC 295 ms
52,412 KB
testcase_08 AC 272 ms
52,452 KB
testcase_09 WA -
testcase_10 AC 281 ms
52,500 KB
testcase_11 AC 335 ms
52,372 KB
testcase_12 AC 298 ms
52,436 KB
testcase_13 AC 285 ms
52,348 KB
testcase_14 AC 284 ms
52,424 KB
testcase_15 WA -
testcase_16 AC 283 ms
52,536 KB
testcase_17 WA -
testcase_18 AC 272 ms
52,360 KB
testcase_19 AC 292 ms
52,328 KB
testcase_20 AC 298 ms
52,496 KB
testcase_21 AC 312 ms
52,564 KB
testcase_22 AC 273 ms
52,548 KB
testcase_23 AC 276 ms
52,380 KB
testcase_24 AC 266 ms
52,564 KB
testcase_25 AC 268 ms
52,360 KB
testcase_26 AC 277 ms
52,468 KB
testcase_27 AC 274 ms
52,392 KB
testcase_28 AC 322 ms
52,468 KB
testcase_29 AC 369 ms
52,344 KB
testcase_30 AC 316 ms
52,552 KB
testcase_31 AC 293 ms
52,384 KB
testcase_32 AC 323 ms
52,548 KB
testcase_33 AC 265 ms
52,560 KB
testcase_34 AC 267 ms
52,396 KB
testcase_35 AC 269 ms
52,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<boost/multiprecision/cpp_int.hpp>
namespace mp=boost::multiprecision;
using Int=mp::cpp_int;

using ll=Int;
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 ? ll(-1) : 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);
}

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<<ans<<endl;
    
    return 0;
}
0