結果

問題 No.135 とりあえず1次元の問題
ユーザー ayaaya
提出日時 2019-07-30 15:15:58
言語 PHP
(8.3.4)
結果
AC  
実行時間 162 ms / 5,000 ms
コード長 1,048 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 18,312 KB
実行使用メモリ 26,948 KB
最終ジャッジ日時 2023-09-18 01:22:07
合計ジャッジ時間 3,103 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 162 ms
26,948 KB
testcase_01 AC 16 ms
18,824 KB
testcase_02 AC 16 ms
18,760 KB
testcase_03 AC 16 ms
18,928 KB
testcase_04 AC 17 ms
18,760 KB
testcase_05 AC 17 ms
18,724 KB
testcase_06 AC 16 ms
18,768 KB
testcase_07 AC 16 ms
18,620 KB
testcase_08 AC 16 ms
18,792 KB
testcase_09 AC 17 ms
18,792 KB
testcase_10 AC 16 ms
18,656 KB
testcase_11 AC 16 ms
18,784 KB
testcase_12 AC 16 ms
18,816 KB
testcase_13 AC 16 ms
18,740 KB
testcase_14 AC 17 ms
18,852 KB
testcase_15 AC 16 ms
18,752 KB
testcase_16 AC 17 ms
18,864 KB
testcase_17 AC 16 ms
18,780 KB
testcase_18 AC 16 ms
18,796 KB
testcase_19 AC 17 ms
18,820 KB
testcase_20 AC 17 ms
18,728 KB
testcase_21 AC 125 ms
26,820 KB
testcase_22 AC 158 ms
26,916 KB
evil01.txt AC 151 ms
26,956 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=$input[0]-$input[1];

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