結果

問題 No.110 しましまピラミッド
ユーザー htensaihtensai
提出日時 2020-01-01 21:56:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 2,116 bytes
コンパイル時間 3,962 ms
コンパイル使用メモリ 74,264 KB
実行使用メモリ 56,076 KB
最終ジャッジ日時 2023-08-14 17:59:07
合計ジャッジ時間 8,060 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
56,020 KB
testcase_01 AC 124 ms
55,628 KB
testcase_02 AC 124 ms
56,020 KB
testcase_03 AC 123 ms
55,580 KB
testcase_04 AC 127 ms
55,836 KB
testcase_05 AC 126 ms
55,840 KB
testcase_06 AC 127 ms
55,752 KB
testcase_07 AC 125 ms
55,840 KB
testcase_08 AC 125 ms
55,992 KB
testcase_09 AC 128 ms
55,820 KB
testcase_10 AC 126 ms
55,948 KB
testcase_11 AC 127 ms
55,896 KB
testcase_12 AC 127 ms
56,076 KB
testcase_13 AC 126 ms
55,976 KB
testcase_14 AC 128 ms
56,000 KB
testcase_15 AC 126 ms
56,016 KB
testcase_16 AC 125 ms
55,992 KB
testcase_17 AC 125 ms
56,028 KB
testcase_18 AC 123 ms
56,000 KB
testcase_19 AC 126 ms
55,648 KB
testcase_20 AC 124 ms
55,756 KB
testcase_21 AC 125 ms
55,580 KB
testcase_22 AC 124 ms
55,592 KB
testcase_23 AC 125 ms
55,952 KB
testcase_24 AC 124 ms
55,968 KB
testcase_25 AC 122 ms
55,508 KB
testcase_26 AC 127 ms
55,860 KB
testcase_27 AC 126 ms
55,820 KB
testcase_28 AC 125 ms
55,740 KB
testcase_29 AC 126 ms
55,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int nw = sc.nextInt();
        int[] wArr = new int[nw];
        for (int i = 0; i < nw; i++) {
            wArr[i] = sc.nextInt();
        }
        int nb = sc.nextInt();
        int[] bArr = new int[nb];
        for (int i = 0; i < nb; i++) {
            bArr[i] = sc.nextInt();
        }
        Arrays.sort(wArr);
        Arrays.sort(bArr);
        int wIdx = nw - 1;
        int bIdx = nb - 1;
        int wCount = 0;
        int prev = Integer.MAX_VALUE;
        while (true) {
            if (wCount % 2 == 0) {
                if (wIdx < 0) {
                    break;
                }
                if (wArr[wIdx] < prev) {
                    wCount++;
                    prev = wArr[wIdx];
                    wIdx--;
                } else {
                    wIdx--;
                }
            } else {
                if (bIdx < 0) {
                    break;
                }
                if (bArr[bIdx] < prev) {
                    wCount++;
                    prev = bArr[bIdx];
                    bIdx--;
                } else {
                    bIdx--;
                }
            }
        }
        wIdx = nw - 1;
        bIdx = nb - 1;
        int bCount = 0;
        prev = Integer.MAX_VALUE;
        while (true) {
            if (bCount % 2 == 1) {
                if (wIdx < 0) {
                    break;
                }
                if (wArr[wIdx] < prev) {
                    bCount++;
                    prev = wArr[wIdx];
                    wIdx--;
                } else {
                    wIdx--;
                }
            } else {
                if (bIdx < 0) {
                    break;
                }
                if (bArr[bIdx] < prev) {
                    bCount++;
                    prev = bArr[bIdx];
                    bIdx--;
                } else {
                    bIdx--;
                }
            }
        }
        System.out.println(Math.max(wCount, bCount));
    }
}
0