結果

問題 No.190 Dry Wet Moist
ユーザー htensaihtensai
提出日時 2020-01-14 17:47:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 832 ms / 2,000 ms
コード長 1,572 bytes
コンパイル時間 2,238 ms
コンパイル使用メモリ 79,476 KB
実行使用メモリ 59,976 KB
最終ジャッジ日時 2024-06-07 17:06:01
合計ジャッジ時間 17,538 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
42,796 KB
testcase_01 AC 141 ms
42,648 KB
testcase_02 AC 151 ms
42,644 KB
testcase_03 AC 156 ms
42,724 KB
testcase_04 AC 156 ms
42,652 KB
testcase_05 AC 154 ms
42,688 KB
testcase_06 AC 152 ms
42,852 KB
testcase_07 AC 213 ms
45,860 KB
testcase_08 AC 207 ms
45,536 KB
testcase_09 AC 199 ms
45,008 KB
testcase_10 AC 185 ms
43,300 KB
testcase_11 AC 203 ms
44,716 KB
testcase_12 AC 680 ms
51,648 KB
testcase_13 AC 700 ms
53,952 KB
testcase_14 AC 623 ms
49,212 KB
testcase_15 AC 712 ms
53,908 KB
testcase_16 AC 780 ms
56,136 KB
testcase_17 AC 365 ms
48,952 KB
testcase_18 AC 602 ms
49,464 KB
testcase_19 AC 770 ms
57,812 KB
testcase_20 AC 584 ms
53,024 KB
testcase_21 AC 325 ms
48,868 KB
testcase_22 AC 828 ms
59,976 KB
testcase_23 AC 785 ms
59,112 KB
testcase_24 AC 832 ms
59,688 KB
testcase_25 AC 153 ms
42,300 KB
testcase_26 AC 153 ms
42,696 KB
testcase_27 AC 683 ms
53,612 KB
testcase_28 AC 567 ms
48,868 KB
testcase_29 AC 612 ms
49,076 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