結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 162 ms
52,340 KB
testcase_01 AC 163 ms
52,320 KB
testcase_02 AC 161 ms
52,408 KB
testcase_03 AC 203 ms
52,480 KB
testcase_04 AC 201 ms
52,400 KB
testcase_05 AC 191 ms
52,352 KB
testcase_06 AC 207 ms
52,428 KB
testcase_07 AC 199 ms
52,320 KB
testcase_08 AC 163 ms
52,680 KB
testcase_09 WA -
testcase_10 AC 169 ms
52,364 KB
testcase_11 AC 171 ms
52,444 KB
testcase_12 AC 201 ms
52,408 KB
testcase_13 AC 182 ms
52,352 KB
testcase_14 AC 184 ms
52,352 KB
testcase_15 WA -
testcase_16 AC 188 ms
52,376 KB
testcase_17 WA -
testcase_18 AC 170 ms
52,440 KB
testcase_19 AC 192 ms
52,368 KB
testcase_20 AC 204 ms
52,364 KB
testcase_21 AC 207 ms
52,360 KB
testcase_22 AC 172 ms
52,348 KB
testcase_23 AC 192 ms
52,324 KB
testcase_24 AC 166 ms
52,392 KB
testcase_25 AC 166 ms
52,568 KB
testcase_26 AC 178 ms
52,396 KB
testcase_27 AC 173 ms
52,524 KB
testcase_28 AC 203 ms
52,364 KB
testcase_29 AC 233 ms
52,368 KB
testcase_30 AC 204 ms
52,352 KB
testcase_31 AC 183 ms
52,400 KB
testcase_32 AC 207 ms
52,416 KB
testcase_33 AC 165 ms
52,356 KB
testcase_34 AC 163 ms
52,492 KB
testcase_35 AC 160 ms
52,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll=__int128;
struct T{
    ll v;
    long long cnt;
    long long bad;
};
T e=T{0,0,0};
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;
vector<T> B(MAX_N,e);


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,e);
    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,e);
    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;
    ll deb=0;
    vector<T> A(MAX_N,e);
    for(int i=0;i<n;i++){
        long long tmp;
        cin>>tmp;
        if(tmp==-1) deb++;
        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;
    }
    long long x=0,y=0;
    for(int i=0;i<n;i++){
        x+=B[i].cnt;
        y+=B[i].bad;
    }
    
    cerr<<x<<" "<<y<<endl;
    cerr<<((long long)n)*n<<" "<<(long long)(2*deb*n-deb*deb)<<endl;
    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