結果

問題 No.110 しましまピラミッド
ユーザー YamaKasaYamaKasa
提出日時 2018-07-07 22:35:34
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,466 bytes
コンパイル時間 3,212 ms
コンパイル使用メモリ 74,448 KB
実行使用メモリ 58,160 KB
最終ジャッジ日時 2023-09-19 04:55:38
合計ジャッジ時間 7,889 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,756 KB
testcase_01 AC 127 ms
55,776 KB
testcase_02 AC 128 ms
53,792 KB
testcase_03 AC 127 ms
56,144 KB
testcase_04 AC 129 ms
56,004 KB
testcase_05 AC 130 ms
55,580 KB
testcase_06 AC 130 ms
55,564 KB
testcase_07 AC 129 ms
56,004 KB
testcase_08 AC 127 ms
55,608 KB
testcase_09 AC 130 ms
55,820 KB
testcase_10 AC 127 ms
55,748 KB
testcase_11 AC 127 ms
55,512 KB
testcase_12 AC 128 ms
55,980 KB
testcase_13 AC 127 ms
55,592 KB
testcase_14 AC 129 ms
55,904 KB
testcase_15 AC 128 ms
55,820 KB
testcase_16 AC 130 ms
55,920 KB
testcase_17 AC 128 ms
55,768 KB
testcase_18 AC 126 ms
55,892 KB
testcase_19 AC 130 ms
55,908 KB
testcase_20 AC 129 ms
55,936 KB
testcase_21 AC 129 ms
55,832 KB
testcase_22 AC 127 ms
55,756 KB
testcase_23 AC 131 ms
56,036 KB
testcase_24 AC 131 ms
55,756 KB
testcase_25 AC 130 ms
56,168 KB
testcase_26 AC 129 ms
55,756 KB
testcase_27 AC 128 ms
55,720 KB
testcase_28 AC 129 ms
55,752 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; 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; 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