結果

問題 No.275 中央値を求めよ
ユーザー yu_017yu_017
提出日時 2019-01-14 10:54:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 348 ms / 1,000 ms
コード長 633 bytes
コンパイル時間 3,158 ms
コンパイル使用メモリ 73,464 KB
実行使用メモリ 57,808 KB
最終ジャッジ日時 2023-09-01 03:17:35
合計ジャッジ時間 13,480 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
55,976 KB
testcase_01 AC 119 ms
55,580 KB
testcase_02 AC 140 ms
55,840 KB
testcase_03 AC 120 ms
56,208 KB
testcase_04 AC 120 ms
56,536 KB
testcase_05 AC 118 ms
56,364 KB
testcase_06 AC 133 ms
55,924 KB
testcase_07 AC 217 ms
57,028 KB
testcase_08 AC 149 ms
56,196 KB
testcase_09 AC 146 ms
56,364 KB
testcase_10 AC 143 ms
55,964 KB
testcase_11 AC 117 ms
56,680 KB
testcase_12 AC 119 ms
56,100 KB
testcase_13 AC 118 ms
56,412 KB
testcase_14 AC 119 ms
56,496 KB
testcase_15 AC 304 ms
56,920 KB
testcase_16 AC 182 ms
56,280 KB
testcase_17 AC 177 ms
56,456 KB
testcase_18 AC 163 ms
56,400 KB
testcase_19 AC 250 ms
57,408 KB
testcase_20 AC 267 ms
57,460 KB
testcase_21 AC 197 ms
56,744 KB
testcase_22 AC 299 ms
57,312 KB
testcase_23 AC 193 ms
56,956 KB
testcase_24 AC 152 ms
56,316 KB
testcase_25 AC 342 ms
57,612 KB
testcase_26 AC 294 ms
57,044 KB
testcase_27 AC 266 ms
57,160 KB
testcase_28 AC 132 ms
55,948 KB
testcase_29 AC 198 ms
56,480 KB
testcase_30 AC 139 ms
56,164 KB
testcase_31 AC 303 ms
56,988 KB
testcase_32 AC 145 ms
56,964 KB
testcase_33 AC 284 ms
57,340 KB
testcase_34 AC 133 ms
56,688 KB
testcase_35 AC 228 ms
57,280 KB
testcase_36 AC 188 ms
56,016 KB
testcase_37 AC 146 ms
56,472 KB
testcase_38 AC 162 ms
56,220 KB
testcase_39 AC 161 ms
55,920 KB
testcase_40 AC 348 ms
57,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.LinkedList;
import java.util.Scanner;

public class A000275 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		LinkedList<Integer> a = new LinkedList<>();
		for(int i=0;i<n;i++) {
			int t = sc.nextInt();
			if(i==0) {
				a.add(t);
				continue;
			}
			if(a.get(a.size()-1)<=t) {
				a.addLast(t);
				continue;
			}
			for(int j=0;j<a.size();j++) {
				if(t<a.get(j)) {
					a.add(j, t);
					break;
				}
			}
		}
		sc.close();

		if(n%2==1) {
			System.out.println(a.get(n/2));
		}else {
			System.out.println((a.get(n/2-1)+a.get(n/2))/2f);
		}

	}

}
0