結果

問題 No.110 しましまピラミッド
ユーザー YamaKasaYamaKasa
提出日時 2018-07-07 22:34:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,474 bytes
コンパイル時間 2,382 ms
コンパイル使用メモリ 74,592 KB
実行使用メモリ 56,444 KB
最終ジャッジ日時 2023-09-19 04:53:52
合計ジャッジ時間 8,041 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
56,124 KB
testcase_01 AC 132 ms
55,836 KB
testcase_02 AC 127 ms
55,928 KB
testcase_03 AC 131 ms
56,252 KB
testcase_04 AC 127 ms
55,764 KB
testcase_05 AC 131 ms
55,868 KB
testcase_06 AC 128 ms
55,740 KB
testcase_07 AC 130 ms
56,092 KB
testcase_08 AC 131 ms
55,828 KB
testcase_09 AC 128 ms
55,820 KB
testcase_10 AC 126 ms
55,856 KB
testcase_11 AC 127 ms
56,108 KB
testcase_12 AC 127 ms
55,880 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 131 ms
55,852 KB
testcase_18 AC 133 ms
56,172 KB
testcase_19 AC 131 ms
55,892 KB
testcase_20 AC 132 ms
55,888 KB
testcase_21 AC 130 ms
55,856 KB
testcase_22 AC 129 ms
56,116 KB
testcase_23 AC 129 ms
56,204 KB
testcase_24 AC 132 ms
55,936 KB
testcase_25 AC 128 ms
56,020 KB
testcase_26 AC 130 ms
55,760 KB
testcase_27 AC 131 ms
56,216 KB
testcase_28 AC 130 ms
55,740 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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 max1 = 1;
		int h = W[Nw - 1];
		int flag = 0;
		for(int i = Nw - 1; 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 = Nb - 1; 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