結果

問題 No.190 Dry Wet Moist
ユーザー htensaihtensai
提出日時 2020-01-14 17:47:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 787 ms / 2,000 ms
コード長 1,572 bytes
コンパイル時間 3,474 ms
コンパイル使用メモリ 76,384 KB
実行使用メモリ 66,148 KB
最終ジャッジ日時 2023-08-26 21:37:08
合計ジャッジ時間 16,314 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
57,128 KB
testcase_01 AC 154 ms
56,716 KB
testcase_02 AC 157 ms
56,808 KB
testcase_03 AC 160 ms
56,796 KB
testcase_04 AC 161 ms
57,168 KB
testcase_05 AC 159 ms
56,984 KB
testcase_06 AC 157 ms
56,732 KB
testcase_07 AC 220 ms
60,060 KB
testcase_08 AC 217 ms
60,632 KB
testcase_09 AC 199 ms
58,976 KB
testcase_10 AC 206 ms
58,464 KB
testcase_11 AC 240 ms
58,700 KB
testcase_12 AC 601 ms
61,912 KB
testcase_13 AC 631 ms
65,092 KB
testcase_14 AC 598 ms
61,444 KB
testcase_15 AC 638 ms
64,696 KB
testcase_16 AC 710 ms
64,500 KB
testcase_17 AC 363 ms
60,700 KB
testcase_18 AC 528 ms
61,332 KB
testcase_19 AC 698 ms
65,228 KB
testcase_20 AC 607 ms
64,972 KB
testcase_21 AC 346 ms
60,960 KB
testcase_22 AC 776 ms
65,052 KB
testcase_23 AC 760 ms
66,148 KB
testcase_24 AC 787 ms
65,232 KB
testcase_25 AC 156 ms
57,008 KB
testcase_26 AC 166 ms
56,952 KB
testcase_27 AC 677 ms
65,112 KB
testcase_28 AC 482 ms
61,300 KB
testcase_29 AC 533 ms
62,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n * 2];
        for (int i = 0; i < 2 * n; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        int left1 = 0;
        int left2 = 0;
        int left3 = 0;
        int right1 = n * 2 - 1;
        int right2 = n * 2 - 1;
        int right3 = n * 2 - 1;
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        while (left1 < right1 || left2 < right2 || left3 < right3) {
            if (left1 < right1) {
                if (arr[left1] + arr[right1] < 0) {
                    left1++;
                    right1--;
                    count1++;
                } else {
                    right1--;
                }
            }
            if (left2 < right2) {
                if (arr[left2] + arr[right2] > 0) {
                    left2++;
                    right2--;
                    count2++;
                } else {
                    left2++;
                }
            }
            if (left3 < right3) {
                if (arr[left3] + arr[right3] == 0) {
                    left3++;
                    right3--;
                    count3++;
                } else if (arr[left3] + arr[right3] < 0){
                    left3++;
                } else {
                    right3--;
                }
            }
        }
        System.out.println(count1 + " " + count2 + " " + count3);
    }
}
0