結果

問題 No.2821 A[i] ← 2A[j] - A[i]
ユーザー tnakao0123
提出日時 2024-07-29 17:20:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 729 bytes
コンパイル時間 380 ms
コンパイル使用メモリ 41,068 KB
最終ジャッジ日時 2025-02-23 19:25:48
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21 WA * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:47:40: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘ll’ {aka ‘long long int’} [-Wformat=]
   47 |   for (int i = 0; i < n; i++) printf("%d\n", ds[i]);
      |                                       ~^     ~~~~~
      |                                        |         |
      |                                        int       ll {aka long long int}
      |                                       %lld
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);
      |                               ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- 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], ds[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);

  ds[0] = 0;
  for (int i = 1; i < n; i++)
    ds[i] = gcd(ds[i - 1], abs(as[i] - as[0]));

  for (int i = 0; i < n; i++) printf("%d\n", ds[i]);
  
  return 0;
}
0