結果

問題 No.110 しましまピラミッド
ユーザー tsunabittsunabit
提出日時 2020-02-24 23:45:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 1,387 bytes
コンパイル時間 4,163 ms
コンパイル使用メモリ 81,388 KB
実行使用メモリ 54,468 KB
最終ジャッジ日時 2024-04-20 20:32:28
合計ジャッジ時間 8,496 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
54,168 KB
testcase_01 AC 125 ms
53,728 KB
testcase_02 AC 111 ms
52,744 KB
testcase_03 AC 123 ms
54,296 KB
testcase_04 AC 123 ms
54,092 KB
testcase_05 AC 120 ms
54,160 KB
testcase_06 AC 120 ms
53,768 KB
testcase_07 AC 121 ms
53,760 KB
testcase_08 AC 111 ms
53,328 KB
testcase_09 AC 124 ms
54,012 KB
testcase_10 AC 109 ms
52,864 KB
testcase_11 AC 127 ms
54,340 KB
testcase_12 AC 123 ms
53,868 KB
testcase_13 AC 120 ms
53,880 KB
testcase_14 AC 120 ms
54,008 KB
testcase_15 AC 121 ms
54,024 KB
testcase_16 AC 108 ms
52,812 KB
testcase_17 AC 117 ms
54,004 KB
testcase_18 AC 122 ms
54,236 KB
testcase_19 AC 112 ms
52,596 KB
testcase_20 AC 126 ms
53,940 KB
testcase_21 AC 106 ms
52,716 KB
testcase_22 AC 107 ms
52,956 KB
testcase_23 AC 116 ms
54,052 KB
testcase_24 AC 123 ms
54,364 KB
testcase_25 AC 109 ms
52,740 KB
testcase_26 AC 123 ms
54,124 KB
testcase_27 AC 107 ms
52,804 KB
testcase_28 AC 121 ms
54,468 KB
testcase_29 AC 124 ms
54,092 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