結果

問題 No.983 Convolution
ユーザー pekempey
提出日時 2020-02-14 12:05:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 479 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 71,344 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-06 07:51:34
合計ジャッジ時間 3,948 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

using ll = long long;

ll gcd(ll x, ll y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    ll g = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] != -1) {
            g = gcd(g, A[i]);
        }
    }
    if (g == 0) {
        cout << -1 << endl;
    } else {
        cout << g * g << endl;
    }
}
0