結果

問題 No.190 Dry Wet Moist
ユーザー htensai
提出日時 2020-01-14 17:47:32
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,172 ms / 2,000 ms
コード長 1,572 bytes
コンパイル時間 3,226 ms
コンパイル使用メモリ 79,480 KB
実行使用メモリ 58,020 KB
最終ジャッジ日時 2024-12-26 00:32:32
合計ジャッジ時間 23,776 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

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