結果
| 問題 |
No.406 鴨等間隔の法則
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2016-08-05 22:55:11 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 2,000 ms |
| コード長 | 802 bytes |
| コンパイル時間 | 119 ms |
| コンパイル使用メモリ | 23,040 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-07 11:30:52 |
| 合計ジャッジ時間 | 1,458 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
32 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:33:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | for(int i = 0; i < n; i++) { scanf("%d", &x[i]); }
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <stdio.h>
int n, x[100000];
int y[100000];
void sort(int l, int r) {
if(r - l < 2) { return; }
int m = (r + l) / 2;
sort(l, m);
sort(m, r);
int ll = l, rr = m, cc = l;
while(ll < m || rr < r) {
bool flag;
if(rr == r) { flag = true; }
else if(ll == m) { flag = false; }
else if(x[ll] <= x[rr]) { flag = true; }
else { flag = false; }
if(flag) { y[cc++] = x[ll++]; }
else { y[cc++] = x[rr++]; }
}
for(cc = l; cc < r; cc++) { x[cc] = y[cc]; }
return;
}
int main() {
scanf("%d", &n);
for(int i = 0; i < n; i++) { scanf("%d", &x[i]); }
sort(0, n);
int d = x[1] - x[0];
bool ans = false;
if(d != 0) {
ans = true;
for(int i = 1; i < n; i++) {
ans &= (x[i] - x[i - 1] == d);
}
}
printf("%s\n", ans ? "YES" : "NO");
return 0;
}
FF256grhy