結果

問題 No.406 鴨等間隔の法則
ユーザー ilplrr
提出日時 2018-02-18 18:12:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 452 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 58,972 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-07 12:19:49
合計ジャッジ時間 2,408 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:9: warning: ‘d’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   21 |         if (a[i + 1] - a[i] != d) return cout << "NO\n", 0;
      |         ^~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
using namespace std;

int main()
{
    int n;
    cin >> n;

    int a[n];
    for (auto& x : a) cin >> x;

    sort(a, a + n);

    int d;
    for (int i = 0; i < n - 1; i++) {
        if (a[i] == a[i + 1]) return cout << "NO\n", 0;
        if (!i) d = a[i + 1] - a[i];
        if (a[i + 1] - a[i] != d) return cout << "NO\n", 0;
    }
    cout << "YES\n";

    return 0;
}
0