結果

問題 No.110 しましまピラミッド
ユーザー tenten
提出日時 2020-12-28 15:31:31
言語 Java
(openjdk 23)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 1,706 bytes
コンパイル時間 2,673 ms
コンパイル使用メモリ 77,896 KB
実行使用メモリ 54,320 KB
最終ジャッジ日時 2024-10-03 05:41:19
合計ジャッジ時間 7,019 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int wn = sc.nextInt();
        int[] wArr = new int[wn];
        for (int i = 0; i < wn; i++) {
            wArr[i] = sc.nextInt();
        }
        Arrays.sort(wArr);
        int bn = sc.nextInt();
        int[] bArr = new int[bn];
        for (int i = 0; i < bn; i++) {
            bArr[i] = sc.nextInt();
        }
        Arrays.sort(bArr);
        int wIdx = wn - 1;
        int bIdx = bn - 1;
        int wCount = 0;
        int wPrev = Integer.MAX_VALUE;
        while (true) {
            while (wIdx >= 0 && wPrev <= wArr[wIdx]) {
                wIdx--;
            }
            if (wIdx < 0) {
                break;
            }
            wCount++;
            wPrev = wArr[wIdx]; 
            while (bIdx >= 0 && wPrev <= bArr[bIdx]) {
                bIdx--;
            }
            if (bIdx < 0) {
                break;
            }
            wCount++;
            wPrev = bArr[bIdx]; 
        }
        wIdx = wn - 1;
        bIdx = bn - 1;
        int bCount = 0;
        int bPrev = Integer.MAX_VALUE;
        while (true) {
            while (bIdx >= 0 && bPrev <= bArr[bIdx]) {
                bIdx--;
            }
            if (bIdx < 0) {
                break;
            }
            bCount++;
            bPrev = bArr[bIdx];
            while (wIdx >= 0 && bPrev <= wArr[wIdx]) {
                wIdx--;
            }
            if (wIdx < 0) {
                break;
            }
            bCount++;
            bPrev = wArr[wIdx];
        }
        System.out.println(Math.max(wCount, bCount));
    }
}
0