結果

問題 No.983 Convolution
ユーザー chielochielo
提出日時 2020-02-11 14:05:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 2,312 ms
コンパイル使用メモリ 192,840 KB
最終ジャッジ日時 2025-01-08 23:35:12
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
main.cpp:29:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |         scanf("%lld", a + i);
      |         ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
const int maxn = 1e6 + 3;

int n, m;
ll a[maxn];

void fwt() {
    for(int i = 1; i < m; i *= 2)
    for(int j = 0; j < m; j += i * 2)
    for(int k = 0; k < i; ++k)
        a[j + k] += a[j + k + i];
}

void ifwt() {
    for(int i = 1; i < m; i *= 2)
    for(int j = 0; j < m; j += i * 2)
    for(int k = 0; k < i; ++k)
        a[j + k] -= a[j + k + i];
}

int main() {
    scanf("%d", &n);
    m = 1;
    while(m < n)
        m *= 2;
    for(int i = 0; i < n; ++i) {
        scanf("%lld", a + i);
        if(a[i] == -1)
            a[i] = 0;
    }
    fwt();
    // for(int i = 0; i < m; ++i)
    //     a[i] *= a[i];
    // ifwt();
    ll ans = 0;
    for(int i = 0; i < n; ++i)
        ans = std::__gcd(ans, a[i]);
    printf("%lld\n", ans ? ans * ans : -1);
    return 0;
}
0