結果

問題 No.190 Dry Wet Moist
ユーザー tentententen
提出日時 2021-01-20 11:33:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 823 ms / 2,000 ms
コード長 1,039 bytes
コンパイル時間 2,765 ms
コンパイル使用メモリ 75,896 KB
実行使用メモリ 66,664 KB
最終ジャッジ日時 2023-08-24 14:03:53
合計ジャッジ時間 17,721 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 162 ms
57,096 KB
testcase_01 AC 160 ms
56,804 KB
testcase_02 AC 165 ms
57,052 KB
testcase_03 AC 167 ms
56,836 KB
testcase_04 AC 168 ms
54,980 KB
testcase_05 AC 170 ms
59,012 KB
testcase_06 AC 164 ms
56,948 KB
testcase_07 AC 234 ms
59,956 KB
testcase_08 AC 228 ms
60,864 KB
testcase_09 AC 222 ms
59,012 KB
testcase_10 AC 215 ms
57,200 KB
testcase_11 AC 223 ms
58,760 KB
testcase_12 AC 596 ms
62,996 KB
testcase_13 AC 649 ms
64,740 KB
testcase_14 AC 646 ms
62,076 KB
testcase_15 AC 674 ms
64,824 KB
testcase_16 AC 730 ms
64,956 KB
testcase_17 AC 370 ms
60,676 KB
testcase_18 AC 572 ms
61,288 KB
testcase_19 AC 727 ms
64,932 KB
testcase_20 AC 632 ms
65,320 KB
testcase_21 AC 330 ms
60,900 KB
testcase_22 AC 796 ms
65,672 KB
testcase_23 AC 800 ms
65,420 KB
testcase_24 AC 823 ms
66,664 KB
testcase_25 AC 161 ms
56,784 KB
testcase_26 AC 159 ms
57,248 KB
testcase_27 AC 674 ms
64,884 KB
testcase_28 AC 519 ms
61,568 KB
testcase_29 AC 573 ms
61,752 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 left = 0;
		int right = 2 * n - 1;
		int moist = 0;
		while (left < right) {
		    if (arr[left] + arr[right] < 0) {
		        left++;
		    } else if (arr[left] + arr[right] > 0) {
		        right--;
		    } else {
		        moist++;
		        left++;
		        right--;
		    }
		}
		left = 0;
		right = 2 * n - 1;
		int dry = 0;
		while (left < right) {
		    if (arr[left] + arr[right] < 0) {
		        dry++;
		        left++;
		        right--;
		    } else {
		        right--;
		    }
		}
		left = 0;
		right = 2 * n - 1;
		int wet = 0;
		while (left < right) {
		    if (arr[left] + arr[right] > 0) {
		        wet++;
		        left++;
		        right--;
		    } else {
		        left++;
		    }
		}
		System.out.println(dry + " " + wet + " " + moist);
	}
}
0