結果

問題 No.983 Convolution
ユーザー 👑 Nachia
提出日時 2021-01-20 22:58:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 441 bytes
コンパイル時間 2,514 ms
コンパイル使用メモリ 189,884 KB
最終ジャッジ日時 2025-01-18 02:59:40
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         scanf("%d",&N);
      |         ~~~~~^~~~~~~~~
main.cpp:14:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |         rep(i,N) scanf("%d",&A[i]);
      |                  ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int GCD(int a,int b){ return b?GCD(b,a%b):a; }

int N;
int A[200000];

int main() {
	scanf("%d",&N);
	rep(i,N) scanf("%d",&A[i]);
  int ans=-1;
	rep(i,N){
		if(ans==-1) ans=A[i];
		else if(A[i]!=-1) ans=GCD(ans,A[i]);
	}
	if(ans==-1) printf("-1\n");
	else printf("%lld\n",LL(ans)*LL(ans));
	return 0;
}
0