結果
| 問題 |
No.2821 A[i] ← 2A[j] - A[i]
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-07-29 17:31:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 74 ms / 1,500 ms |
| コード長 | 682 bytes |
| コンパイル時間 | 205 ms |
| コンパイル使用メモリ | 40,316 KB |
| 最終ジャッジ日時 | 2025-02-23 19:25:52 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 33 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:40:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
40 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:41:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
41 | for (int i = 0; i < n; i++) scanf("%lld", as + i);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2821.cc: No.2821 A[i] 竊・2A[j] - A[i] - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 300000;
/* typedef */
using ll = long long;
/* global variables */
ll as[MAX_N];
/* subroutines */
template <typename T>
T gcd(T m, T n) { // m >= 0, n >= 0
if (m < n) swap(m, n);
while (n > 0) {
T r = m % n;
m = n;
n = r;
}
return m;
}
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%lld", as + i);
ll g = 0;
for (int i = 0; i < n; i++) {
g = gcd(g, abs(as[i] - as[0]));
printf("%lld\n", g);
}
return 0;
}
tnakao0123