結果

問題 No.190 Dry Wet Moist
ユーザー GrenacheGrenache
提出日時 2016-06-07 21:35:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 499 ms / 2,000 ms
コード長 2,942 bytes
コンパイル時間 4,112 ms
コンパイル使用メモリ 79,760 KB
実行使用メモリ 58,888 KB
最終ジャッジ日時 2024-04-17 06:06:17
合計ジャッジ時間 12,808 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
41,344 KB
testcase_01 AC 119 ms
40,976 KB
testcase_02 AC 119 ms
41,304 KB
testcase_03 AC 121 ms
41,284 KB
testcase_04 AC 121 ms
41,256 KB
testcase_05 AC 121 ms
41,424 KB
testcase_06 AC 122 ms
41,408 KB
testcase_07 AC 135 ms
41,400 KB
testcase_08 AC 127 ms
41,640 KB
testcase_09 AC 126 ms
41,596 KB
testcase_10 AC 124 ms
41,700 KB
testcase_11 AC 125 ms
41,704 KB
testcase_12 AC 360 ms
54,252 KB
testcase_13 AC 359 ms
55,100 KB
testcase_14 AC 323 ms
51,684 KB
testcase_15 AC 364 ms
55,240 KB
testcase_16 AC 420 ms
58,724 KB
testcase_17 AC 204 ms
43,856 KB
testcase_18 AC 315 ms
52,236 KB
testcase_19 AC 412 ms
58,888 KB
testcase_20 AC 349 ms
54,692 KB
testcase_21 AC 186 ms
43,136 KB
testcase_22 AC 450 ms
58,108 KB
testcase_23 AC 499 ms
57,904 KB
testcase_24 AC 483 ms
57,572 KB
testcase_25 AC 123 ms
41,732 KB
testcase_26 AC 122 ms
41,524 KB
testcase_27 AC 377 ms
54,908 KB
testcase_28 AC 276 ms
49,060 KB
testcase_29 AC 312 ms
49,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
		}
	}
}
0