結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 158 ms
52,428 KB
testcase_01 AC 159 ms
52,420 KB
testcase_02 AC 159 ms
52,352 KB
testcase_03 AC 199 ms
52,404 KB
testcase_04 AC 192 ms
52,480 KB
testcase_05 AC 186 ms
52,392 KB
testcase_06 AC 205 ms
52,360 KB
testcase_07 WA -
testcase_08 AC 165 ms
52,480 KB
testcase_09 WA -
testcase_10 AC 161 ms
52,392 KB
testcase_11 AC 167 ms
52,432 KB
testcase_12 WA -
testcase_13 AC 175 ms
52,356 KB
testcase_14 AC 176 ms
52,336 KB
testcase_15 WA -
testcase_16 AC 181 ms
52,316 KB
testcase_17 AC 196 ms
52,428 KB
testcase_18 AC 164 ms
52,416 KB
testcase_19 AC 185 ms
52,448 KB
testcase_20 WA -
testcase_21 AC 208 ms
52,512 KB
testcase_22 AC 164 ms
52,332 KB
testcase_23 AC 178 ms
52,360 KB
testcase_24 AC 163 ms
52,420 KB
testcase_25 AC 161 ms
52,516 KB
testcase_26 AC 173 ms
52,504 KB
testcase_27 AC 164 ms
52,364 KB
testcase_28 AC 209 ms
52,468 KB
testcase_29 AC 237 ms
52,404 KB
testcase_30 AC 191 ms
52,540 KB
testcase_31 AC 175 ms
52,356 KB
testcase_32 WA -
testcase_33 AC 156 ms
52,444 KB
testcase_34 AC 157 ms
52,388 KB
testcase_35 AC 158 ms
52,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll=__int128;
struct T{
    ll v;
    long long cnt;
    long long bad;
};

T operator+(T lhs,T rhs){
    return T{lhs.v+rhs.v,lhs.cnt+rhs.cnt,lhs.bad+rhs.bad};
}
T operator-(T lhs,T rhs){
    return T{lhs.v-rhs.v,lhs.cnt-rhs.cnt,lhs.bad-rhs.bad};
}
T operator*(T lhs,T rhs){
    return T{lhs.v*rhs.v,lhs.cnt*rhs.cnt,lhs.bad*rhs.cnt+lhs.cnt*rhs.bad-lhs.bad*rhs.bad};
}

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;
T B[MAX_N];


void solve(int step,vector<T> A,int mask){
    if(A.size()==1){
        B[mask]=B[mask]+A[0]*A[0];
        return;
    }
    vector<T> 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<T> even(A.size()/2);
    for(int i=0;i<A.size();i++) even[i/2]=even[i/2]+A[i];
    solve(step+1,even,mask);
    for(int i=0;i<A.size()/2;i++){
        int id = ((i*2)<<step)+mask;
        B[id]=B[id]-B[id+1];
    }
}

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<T> A(MAX_N);
    for(int i=0;i<n;i++){
        long long tmp;
        cin>>tmp;
        if(tmp==-1) A[i]={0,1,-1};
        else A[i]={tmp,1,0};
    }

    solve(0,A,0);

    vector<ll> B2(MAX_N);
    for(int i=0;i<MAX_N;i++){
        if(B[i].bad==0) B2[i]=B[i].v;
        else B2[i]=0;
    }

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