結果

問題 No.135 とりあえず1次元の問題
ユーザー ayaaya
提出日時 2019-07-30 15:16:57
言語 PHP
(8.3.4)
結果
AC  
実行時間 158 ms / 5,000 ms
コード長 1,030 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 18,560 KB
実行使用メモリ 26,884 KB
最終ジャッジ日時 2023-09-18 01:25:06
合計ジャッジ時間 2,304 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 158 ms
26,872 KB
testcase_01 AC 17 ms
18,708 KB
testcase_02 AC 16 ms
18,776 KB
testcase_03 AC 16 ms
18,688 KB
testcase_04 AC 16 ms
18,820 KB
testcase_05 AC 16 ms
18,768 KB
testcase_06 AC 16 ms
18,776 KB
testcase_07 AC 17 ms
18,748 KB
testcase_08 AC 16 ms
18,780 KB
testcase_09 AC 16 ms
18,784 KB
testcase_10 AC 16 ms
18,800 KB
testcase_11 AC 17 ms
18,796 KB
testcase_12 AC 16 ms
18,820 KB
testcase_13 AC 16 ms
18,816 KB
testcase_14 AC 17 ms
18,776 KB
testcase_15 AC 16 ms
18,680 KB
testcase_16 AC 17 ms
18,652 KB
testcase_17 AC 17 ms
18,748 KB
testcase_18 AC 16 ms
18,704 KB
testcase_19 AC 16 ms
18,708 KB
testcase_20 AC 16 ms
18,792 KB
testcase_21 AC 123 ms
26,848 KB
testcase_22 AC 156 ms
26,884 KB
evil01.txt AC 151 ms
26,648 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)));

rsort($input);
$ans=0;

for($i=1;$i<=$n-1;$i++){
  $diff=$input[$i-1]-$input[$i];
  if($ans==0){
    $ans=$diff;
  }elseif($diff<$ans && $diff!=0){
    $ans=$diff;
  }
}
echo $ans;

?>
0