結果
問題 | No.110 しましまピラミッド |
ユーザー |
|
提出日時 | 2015-11-26 23:04:38 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 139 ms / 5,000 ms |
コード長 | 1,562 bytes |
コンパイル時間 | 4,022 ms |
コンパイル使用メモリ | 78,168 KB |
実行使用メモリ | 54,520 KB |
最終ジャッジ日時 | 2024-12-31 11:13:48 |
合計ジャッジ時間 | 9,108 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
import java.util.Arrays; import java.util.Scanner; public class Main_yukicoder110 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int nw = sc.nextInt(); int[] w = new int[nw]; for (int i = 0; i < nw; i++) { w[i] = sc.nextInt(); } Arrays.sort(w); int nb = sc.nextInt(); int[] b = new int[nb]; for (int i = 0; i < nb; i++) { b[i] = sc.nextInt(); } Arrays.sort(b); int prev = Integer.MAX_VALUE; int iw = nw - 1; int ib = nb - 1; int i; for (i = 0; iw >= 0 && ib >= 0; i++) { if (i % 2 == 0) { while (iw >= 0 && w[iw] >= prev) { iw--; } if (iw >= 0) { prev = w[iw]; } } else { while (ib >= 0 && b[ib] >= prev) { ib--; } if (ib >= 0) { prev = b[ib]; } } } int ret = i; prev = Integer.MAX_VALUE; iw = nw - 1; ib = nb - 1; for (i = 0; iw >= 0 && ib >= 0; i++) { if (i % 2 == 1) { while (iw >= 0 && w[iw] >= prev) { iw--; } if (iw >= 0) { prev = w[iw]; } } else { while (ib >= 0 && b[ib] >= prev) { ib--; } if (ib >= 0) { prev = b[ib]; } } } System.out.println(Math.max(ret, i) - 1); sc.close(); } }