結果
問題 | No.190 Dry Wet Moist |
ユーザー | Grenache |
提出日時 | 2016-06-07 21:35:40 |
言語 | Java21 (openjdk 21) |
結果 |
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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 122 ms
40,976 KB |
testcase_01 | AC | 122 ms
40,796 KB |
testcase_02 | AC | 120 ms
41,036 KB |
testcase_03 | AC | 122 ms
41,456 KB |
testcase_04 | AC | 123 ms
40,752 KB |
testcase_05 | AC | 125 ms
41,316 KB |
testcase_06 | AC | 121 ms
41,016 KB |
testcase_07 | AC | 137 ms
41,396 KB |
testcase_08 | AC | 128 ms
41,496 KB |
testcase_09 | AC | 123 ms
41,632 KB |
testcase_10 | AC | 124 ms
41,284 KB |
testcase_11 | AC | 114 ms
41,656 KB |
testcase_12 | AC | 397 ms
54,052 KB |
testcase_13 | AC | 349 ms
53,940 KB |
testcase_14 | AC | 326 ms
50,888 KB |
testcase_15 | AC | 372 ms
54,276 KB |
testcase_16 | AC | 466 ms
58,516 KB |
testcase_17 | AC | 202 ms
43,316 KB |
testcase_18 | AC | 299 ms
52,428 KB |
testcase_19 | AC | 407 ms
58,396 KB |
testcase_20 | AC | 347 ms
54,328 KB |
testcase_21 | AC | 188 ms
42,484 KB |
testcase_22 | AC | 458 ms
58,048 KB |
testcase_23 | AC | 493 ms
57,344 KB |
testcase_24 | AC | 443 ms
58,044 KB |
testcase_25 | AC | 125 ms
40,976 KB |
testcase_26 | AC | 124 ms
41,356 KB |
testcase_27 | AC | 376 ms
54,524 KB |
testcase_28 | AC | 272 ms
48,628 KB |
testcase_29 | AC | 308 ms
48,728 KB |
ソースコード
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); } } }