#38637: MLE


jane920716@gmail.com (Jane)

學校 : 不指定學校
編號 : 258039
來源 : [123.241.254.185]
最後登入時間 :
2024-04-23 16:45:40
a737. 10041 - Vito's family -- UVa10041 | From: [116.241.11.15] | 發表日期 : 2023-12-11 21:23

請各位大神幫我看看為什麼會出現MLE的情形,感覺程式碼邏輯都正確以及使用隨機測資都可以正常運行QQ,請告訴我該如何修改~

import java.util.*;

public class main{
public static void main(String[] args){
Scanner k = new Scanner(System.in);
int cases = k.nextInt();

for(int i = 0 ;i<cases ;i++){
int num_relative = k.nextInt();
int[] address = new int[num_relative];
int house = 0;
int distan = 0;

for(int j = 0;j<num_relative;j++){
address[j] = k.nextInt();
}
Arrays.sort(address);

house = address[(num_relative/2)];


for(int p =0;p<num_relative;p++){
distan = distan+Math.abs(house - address[p]);
}
System.out.println(distan);
}

}
}

 
#38638: Re: MLE


liaoweichen1024@gmail.com (M_SQRT)

學校 : 新北市立新莊高級中學
編號 : 195452
來源 : [122.116.111.175]
最後登入時間 :
2024-04-30 21:28:05
a737. 10041 - Vito's family -- UVa10041 | From: [118.166.143.199] | 發表日期 : 2023-12-12 00:15

https://zerojudge.tw/ShowThread?postid=38639&reply=0

 
ZeroJudge Forum