結果

問題 No.135 とりあえず1次元の問題
ユーザー ayaaya
提出日時 2019-07-30 15:06:34
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 1,000 bytes
コンパイル時間 795 ms
コンパイル使用メモリ 18,668 KB
実行使用メモリ 26,956 KB
最終ジャッジ日時 2023-09-18 00:54:04
合計ジャッジ時間 3,503 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
26,956 KB
testcase_01 AC 15 ms
18,852 KB
testcase_02 WA -
testcase_03 AC 15 ms
18,820 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 16 ms
18,648 KB
testcase_13 AC 15 ms
18,844 KB
testcase_14 AC 16 ms
18,772 KB
testcase_15 AC 15 ms
18,796 KB
testcase_16 WA -
testcase_17 AC 16 ms
18,840 KB
testcase_18 AC 16 ms
18,860 KB
testcase_19 AC 16 ms
18,800 KB
testcase_20 AC 15 ms
18,848 KB
testcase_21 WA -
testcase_22 WA -
evil01.txt AC 139 ms
26,960 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
/*No.135 とりあえず1次元の問題
問題文
数直線上の整数座標上にN個の点がある。

その中から同じ座標ではない2点を選んで、その2点の距離を求める。
距離は、i番目の点の座標をXi、j番目の点の座標をXjとすると 、
絶対値|Xi−Xj|とする。

この時、最小の距離となる2点を選ぶとして、選んだ2点間の最小距離を求めてください。
条件にあう2点を選べなかったら0を出力してください。

入力
N
X1 X2 … XN
入力は全て整数で与えられる。
・1≤N≤100000=105
・0≤Xi≤1000000=106,1≤i≤N
出力
条件にあう2点間の最小距離を求めてください。
2点を選べなかったら0を出力してください。


*/

$n = trim(fgets(STDIN));
$input=explode(" ",trim(fgets(STDIN)));

sort($input);
$ans=$input[1]-$input[0];

for($i=1;$i<=$n-1;$i++){
  $diff=$input[$i]-$input[$i-1];

  if($diff<$ans){
    $ans=$diff;
  }
}
echo $ans;

?>
0