結果

問題 No.110 しましまピラミッド
ユーザー htensaihtensai
提出日時 2020-01-01 21:56:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 2,116 bytes
コンパイル時間 1,786 ms
コンパイル使用メモリ 78,236 KB
実行使用メモリ 54,488 KB
最終ジャッジ日時 2024-05-02 05:57:26
合計ジャッジ時間 6,169 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
54,048 KB
testcase_01 AC 123 ms
54,240 KB
testcase_02 AC 112 ms
53,996 KB
testcase_03 AC 101 ms
52,996 KB
testcase_04 AC 105 ms
53,192 KB
testcase_05 AC 104 ms
52,780 KB
testcase_06 AC 103 ms
52,952 KB
testcase_07 AC 112 ms
54,316 KB
testcase_08 AC 114 ms
53,976 KB
testcase_09 AC 134 ms
54,068 KB
testcase_10 AC 111 ms
54,112 KB
testcase_11 AC 103 ms
54,488 KB
testcase_12 AC 123 ms
54,140 KB
testcase_13 AC 111 ms
53,476 KB
testcase_14 AC 116 ms
53,776 KB
testcase_15 AC 104 ms
53,064 KB
testcase_16 AC 102 ms
52,836 KB
testcase_17 AC 119 ms
54,156 KB
testcase_18 AC 107 ms
53,300 KB
testcase_19 AC 103 ms
52,972 KB
testcase_20 AC 100 ms
52,708 KB
testcase_21 AC 114 ms
54,104 KB
testcase_22 AC 116 ms
54,260 KB
testcase_23 AC 117 ms
53,944 KB
testcase_24 AC 113 ms
53,928 KB
testcase_25 AC 123 ms
53,968 KB
testcase_26 AC 116 ms
54,280 KB
testcase_27 AC 110 ms
53,864 KB
testcase_28 AC 102 ms
52,760 KB
testcase_29 AC 104 ms
52,940 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