結果

問題 No.110 しましまピラミッド
ユーザー YamaKasaYamaKasa
提出日時 2018-07-07 22:44:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 133 ms / 5,000 ms
コード長 1,499 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 74,048 KB
実行使用メモリ 56,068 KB
最終ジャッジ日時 2023-08-30 04:07:30
合計ジャッジ時間 7,526 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
55,744 KB
testcase_01 AC 129 ms
55,856 KB
testcase_02 AC 130 ms
56,068 KB
testcase_03 AC 129 ms
55,824 KB
testcase_04 AC 128 ms
55,608 KB
testcase_05 AC 129 ms
55,920 KB
testcase_06 AC 131 ms
56,040 KB
testcase_07 AC 131 ms
55,740 KB
testcase_08 AC 128 ms
55,816 KB
testcase_09 AC 129 ms
55,916 KB
testcase_10 AC 128 ms
55,688 KB
testcase_11 AC 129 ms
55,768 KB
testcase_12 AC 129 ms
55,824 KB
testcase_13 AC 129 ms
55,688 KB
testcase_14 AC 131 ms
55,632 KB
testcase_15 AC 130 ms
55,752 KB
testcase_16 AC 131 ms
55,920 KB
testcase_17 AC 133 ms
55,756 KB
testcase_18 AC 129 ms
53,904 KB
testcase_19 AC 131 ms
55,924 KB
testcase_20 AC 132 ms
55,820 KB
testcase_21 AC 130 ms
55,636 KB
testcase_22 AC 129 ms
55,876 KB
testcase_23 AC 132 ms
55,744 KB
testcase_24 AC 131 ms
55,696 KB
testcase_25 AC 128 ms
55,532 KB
testcase_26 AC 130 ms
55,996 KB
testcase_27 AC 131 ms
55,800 KB
testcase_28 AC 129 ms
55,900 KB
testcase_29 AC 130 ms
55,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int Nw = scan.nextInt();
		int []W = new int[Nw];
		for(int i = 0; i < Nw; i++) {
			W[i] = scan.nextInt();
		}
		int Nb = scan.nextInt();
		int []B = new int[Nb];
		for(int i = 0; i < Nb; i++) {
			B[i] = scan.nextInt();
		}
		scan.close();
		Arrays.sort(W);
		Arrays.sort(B);

		// 白が一番下の場合
		int n = Math.max(Nw, Nb);
		int max1 = 1;
		int h = W[Nw - 1];
		int flag = 0;
		for(int i = 2 * n; i >= 0; i--) {
			switch(flag) {
			case 0:
				for(int j = Nb - 1; j >= 0; j--) {
					if(h > B[j]) {
						max1++;
						h = B[j];
						flag = 1;
						break;
					}
				}
				break;
			case 1:
				for(int j = Nw - 2; j >= 0; j--) {
					if(h > W[j]) {
						max1 ++;
						flag = 0;
						h = W[j];
						break;
					}
				}
				break;
			}
		}
		// 黒が一番下の場合
				int max2 = 1;
				int h2 = B[Nb - 1];
				int flag2 = 0;
				for(int i = 2 * n; i >= 0; i--) {
					switch(flag2) {
					case 0:
						for(int j = Nw - 1; j >= 0; j--) {
							if(h2 > W[j]) {
								max2++;
								h2 = W[j];
								flag2 = 1;
								break;
							}
						}
						break;
					case 1:
						for(int j = Nb - 2; j >= 0; j--) {
							if(h2 > B[j]) {
								max2 ++;
								flag2 = 0;
								h2 = B[j];
								break;
							}
						}
						break;
					}
				}
		int ans = Math.max(max1, max2);
		System.out.println(ans);

	}
}
0