結果
問題 | No.190 Dry Wet Moist |
ユーザー |
|
提出日時 | 2016-06-07 21:35:40 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 493 ms / 2,000 ms |
コード長 | 2,942 bytes |
コンパイル時間 | 4,546 ms |
コンパイル使用メモリ | 79,668 KB |
実行使用メモリ | 58,516 KB |
最終ジャッジ日時 | 2024-10-08 18:13:11 |
合計ジャッジ時間 | 13,760 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 28 |
ソースコード
import java.io.*;import java.util.*;public class Main_yukicoder190 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);Printer pr = new Printer(System.out);int n = sc.nextInt();int[] a = new int[2 * n];for (int i = 0; i < 2 * n; i++) {a[i] = sc.nextInt();}Arrays.sort(a);int z = lower_bound(a, -1, 2 * n, 0);int p = upper_bound(a, -1, 2 * n, 0);int wet = 0;int pcnt = 0;for (int i = p, j = p - 1; i < 2 * n; i++) {if (j < 0 || a[j] + a[i] <= 0) {pcnt++;} else {wet++;j--;}}wet += pcnt / 2;int dry = 0;int mcnt = 0;for (int i = z - 1, j = z; i >= 0; i--) {if (j >= 2 * n || a[j] + a[i] >= 0) {mcnt++;} else {dry++;j++;}}dry += mcnt / 2;int moist = 0;for (int i = p, j = z - 1; i < 2 * n && j >= 0; ) {if (a[j] + a[i] == 0) {moist++;i++;j--;} else if (a[j] + a[i] > 0) {j--;} else {i++;}}moist += (p - z) / 2;pr.printf("%d %d %d\n", dry, wet, moist);pr.close();sc.close();}private static int lower_bound(int[] data, int l, int r, int value) {while (r - l > 1) {int mid = l + (r - l) / 2;if (data[mid] >= value) {// if (data[mid] > value) {r = mid;} else {l = mid;}}return r;// return l + 1;}private static int upper_bound(int[] data, int l, int r, int value) {while (r - l > 1) {int mid = l + (r - l) / 2;// if (data[mid] >= value) {if (data[mid] > value) {r = mid;} else {l = mid;}}return r;// return l + 1;}@SuppressWarnings("unused")private static class Scanner {BufferedReader br;Iterator<String> it;Scanner (InputStream in) {br = new BufferedReader(new InputStreamReader(in));}String next() throws RuntimeException {try {if (it == null || !it.hasNext()) {it = Arrays.asList(br.readLine().split(" ")).iterator();}return it.next();} catch (IOException e) {throw new IllegalStateException();}}int nextInt() throws RuntimeException {return Integer.parseInt(next());}long nextLong() throws RuntimeException {return Long.parseLong(next());}float nextFloat() throws RuntimeException {return Float.parseFloat(next());}double nextDouble() throws RuntimeException {return Double.parseDouble(next());}void close() {try {br.close();} catch (IOException e) {// throw new IllegalStateException();}}}private static class Printer extends PrintWriter {Printer(PrintStream out) {super(out);}}}