結果

問題 No.406 鴨等間隔の法則
ユーザー pekempey
提出日時 2016-08-05 22:23:42
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 423 bytes
コンパイル時間 1,085 ms
コンパイル使用メモリ 163,216 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-07 11:17:47
合計ジャッジ時間 2,420 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |                 scanf("%d", &a[i]);
      |                 ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

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

	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a.begin(), a.end());

	int mini = 1e9, maxi = -1e9;
	for (int i = 0; i < n - 1; i++) {
		mini = min(mini, a[i + 1] - a[i]);
		maxi = max(maxi, a[i + 1] - a[i]);
	}

	if (mini == maxi && maxi != 0) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}
0