結果

問題 No.983 Convolution
ユーザー chielo
提出日時 2020-02-11 14:03:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 810 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 192,456 KB
最終ジャッジ日時 2025-01-08 23:34:28
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 : -1);
    return 0;
}
0