結果

問題 No.110 しましまピラミッド
ユーザー tsunabittsunabit
提出日時 2020-02-24 23:45:32
言語 Java19
(openjdk 21)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 1,387 bytes
コンパイル時間 3,892 ms
コンパイル使用メモリ 76,224 KB
実行使用メモリ 58,160 KB
最終ジャッジ日時 2023-08-02 20:25:42
合計ジャッジ時間 8,973 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,944 KB
testcase_01 AC 121 ms
55,820 KB
testcase_02 AC 121 ms
56,356 KB
testcase_03 AC 122 ms
55,820 KB
testcase_04 AC 121 ms
58,160 KB
testcase_05 AC 123 ms
56,016 KB
testcase_06 AC 123 ms
55,904 KB
testcase_07 AC 122 ms
55,980 KB
testcase_08 AC 123 ms
55,752 KB
testcase_09 AC 122 ms
55,720 KB
testcase_10 AC 127 ms
55,824 KB
testcase_11 AC 122 ms
56,180 KB
testcase_12 AC 125 ms
55,888 KB
testcase_13 AC 121 ms
55,644 KB
testcase_14 AC 121 ms
55,752 KB
testcase_15 AC 121 ms
56,508 KB
testcase_16 AC 120 ms
55,756 KB
testcase_17 AC 123 ms
55,888 KB
testcase_18 AC 125 ms
56,120 KB
testcase_19 AC 121 ms
55,968 KB
testcase_20 AC 122 ms
56,092 KB
testcase_21 AC 121 ms
56,144 KB
testcase_22 AC 120 ms
55,828 KB
testcase_23 AC 122 ms
55,744 KB
testcase_24 AC 121 ms
56,140 KB
testcase_25 AC 122 ms
54,160 KB
testcase_26 AC 121 ms
56,016 KB
testcase_27 AC 123 ms
55,408 KB
testcase_28 AC 122 ms
55,836 KB
testcase_29 AC 125 ms
55,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No110 {
	public static int max = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int nw = sc.nextInt();
		Integer[] w = new Integer[nw];
		for(int i = 0; i < nw; i++) {
			w[i] = sc.nextInt();
		}
		Arrays.sort(w, Collections.reverseOrder());
		
		int nb = sc.nextInt();
		Integer[] b = new Integer[nb];
		for(int i = 0; i < nb; i++) {
			b[i] = sc.nextInt();
		}
		Arrays.sort(b, Collections.reverseOrder());
		
		// w起点
		for(int i = 0; i < nw; i++) {
			wb(w, b, "b", w[i], 1);
		}
		// b起点
		for(int i = 0; i < nb; i++) {
			wb(w, b, "w", b[i], 1);
		}
		System.out.println(max);
    }
	
	public static void wb(Integer[] w, Integer[] b, String wbe, int c, int total) {
		boolean f = false;
		// 終了条件
		if(wbe.equals("e")) {
			if(max < total) max = total;
		}
		
		// w
		if(wbe.equals("w")) {
			for(int i = 0; i < w.length; i++) {
				if(w[i] < c) {
					total++;
					c = w[i];
					f = true;
					break;
				}
			}
			if(f) {
				wb(w, b, "b", c, total);
			}else {
				wb(w, b, "e", c, total);
			}
		}
		// b
		if(wbe.equals("b")) {
			for(int i = 0; i < b.length; i++) {
				if(b[i] < c) {
					total++;
					c = b[i];
					f = true;
					break;
				}
			}
			if(f) {
				wb(w, b, "w", c, total);
			}else {
				wb(w, b, "e", c, total);
			}
		}
	}
}
0