結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
ueyus
|
| 提出日時 | 2015-09-09 22:06:49 |
| 言語 | Java (openjdk 23) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,195 bytes |
| コンパイル時間 | 2,427 ms |
| コンパイル使用メモリ | 77,344 KB |
| 実行使用メモリ | 41,548 KB |
| 最終ジャッジ日時 | 2024-07-19 05:05:37 |
| 合計ジャッジ時間 | 8,961 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 38 |
ソースコード
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc = new Scanner(System.in);
String[] inp = sc.nextLine().split(" ");
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(inp[i]);
}
Marge mm = new Marge(n);
mm.sort(a, 0, n);
if (n % 2 == 0) {
if ((a[n / 2 - 1] + a[n / 2]) % 2d > 0) {
System.out.println((a[n / 2 - 1] + a[n / 2]) / 2d);
} else {
System.out.println((a[n / 2 - 1] + a[n / 2]) / 2);
}
} else {
System.out.println(a[n / 2]);
}
}
}
class Marge {
int buf[];
Marge(int n) {
buf = new int[n];
}
void sort(int[] a, int s, int e) {
if (1 >= e - s) return;
int mid = s + (e - s) / 2;
sort(a, s, mid);
sort(a, mid, e);
marge(a, s, mid, e);
}
void marge(int[] a, int s, int mid, int e) {
int i = e - s;
int work[] = new int[i];
int p = 0, m = mid, k = s;
while (s < mid && m < e) {
if (a[s] <= a[m]) {
work[p++] = a[s++];
} else {
work[p++] = a[m++];
}
}
while (s < mid) work[p++] = a[s++];
while (m < e) work[p++] = a[m++];
System.arraycopy(work, 0, a, k, i);
}
}
ueyus