結果

問題 No.983 Convolution
ユーザー nikutto_nikutto_
提出日時 2020-02-12 19:32:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,701 bytes
コンパイル時間 1,755 ms
コンパイル使用メモリ 172,696 KB
実行使用メモリ 52,628 KB
最終ジャッジ日時 2024-04-14 22:57:19
合計ジャッジ時間 9,898 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
52,312 KB
testcase_01 AC 165 ms
52,400 KB
testcase_02 AC 162 ms
52,352 KB
testcase_03 AC 204 ms
52,428 KB
testcase_04 AC 201 ms
52,496 KB
testcase_05 AC 188 ms
52,348 KB
testcase_06 AC 204 ms
52,480 KB
testcase_07 AC 201 ms
52,364 KB
testcase_08 AC 169 ms
52,504 KB
testcase_09 WA -
testcase_10 AC 167 ms
52,376 KB
testcase_11 AC 172 ms
52,548 KB
testcase_12 AC 199 ms
52,540 KB
testcase_13 AC 176 ms
52,628 KB
testcase_14 AC 181 ms
52,396 KB
testcase_15 WA -
testcase_16 AC 188 ms
52,556 KB
testcase_17 WA -
testcase_18 AC 167 ms
52,368 KB
testcase_19 AC 187 ms
52,432 KB
testcase_20 AC 206 ms
52,364 KB
testcase_21 AC 207 ms
52,376 KB
testcase_22 AC 163 ms
52,328 KB
testcase_23 AC 179 ms
52,456 KB
testcase_24 AC 167 ms
52,368 KB
testcase_25 AC 163 ms
52,452 KB
testcase_26 AC 174 ms
52,420 KB
testcase_27 AC 168 ms
52,444 KB
testcase_28 AC 199 ms
52,432 KB
testcase_29 AC 235 ms
52,492 KB
testcase_30 AC 202 ms
52,412 KB
testcase_31 AC 181 ms
52,464 KB
testcase_32 AC 205 ms
52,476 KB
testcase_33 AC 160 ms
52,328 KB
testcase_34 AC 161 ms
52,552 KB
testcase_35 AC 163 ms
52,368 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;
        int id2 = ((i*2+1)<<step)+mask;
        B[id]=B[id]-B[id2];
    }
}

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