結果

問題 No.110 しましまピラミッド
ユーザー リチウムリチウム
提出日時 2014-12-23 23:44:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 5,000 ms
コード長 1,069 bytes
コンパイル時間 3,398 ms
コンパイル使用メモリ 74,388 KB
実行使用メモリ 56,436 KB
最終ジャッジ日時 2023-08-30 03:45:42
合計ジャッジ時間 8,602 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
56,004 KB
testcase_01 AC 123 ms
55,880 KB
testcase_02 AC 127 ms
55,804 KB
testcase_03 AC 132 ms
55,560 KB
testcase_04 AC 127 ms
55,860 KB
testcase_05 AC 126 ms
55,872 KB
testcase_06 AC 127 ms
55,976 KB
testcase_07 AC 127 ms
55,812 KB
testcase_08 AC 125 ms
55,628 KB
testcase_09 AC 126 ms
55,868 KB
testcase_10 AC 126 ms
55,636 KB
testcase_11 AC 128 ms
56,436 KB
testcase_12 AC 126 ms
55,864 KB
testcase_13 AC 129 ms
56,164 KB
testcase_14 AC 126 ms
55,864 KB
testcase_15 AC 128 ms
55,840 KB
testcase_16 AC 128 ms
55,628 KB
testcase_17 AC 129 ms
55,940 KB
testcase_18 AC 129 ms
55,816 KB
testcase_19 AC 129 ms
55,880 KB
testcase_20 AC 127 ms
56,160 KB
testcase_21 AC 128 ms
55,736 KB
testcase_22 AC 128 ms
53,732 KB
testcase_23 AC 129 ms
55,692 KB
testcase_24 AC 129 ms
55,896 KB
testcase_25 AC 128 ms
55,904 KB
testcase_26 AC 126 ms
55,948 KB
testcase_27 AC 127 ms
55,752 KB
testcase_28 AC 129 ms
55,924 KB
testcase_29 AC 131 ms
55,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class LightSwitchingPuzzle {
	
	
	 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();
		 }
		 
		 int nb=sc.nextInt();
		 int b[]=new int[nb];
		 for(int i=0;i<nb;i++){
			 b[i]=sc.nextInt();
		 }
		 
		 Arrays.sort(w);
		 Arrays.sort(b);
		 int noww=nw-1;
		 int nowb=nb-1;
		 boolean B=true;
		 int ansb=1;
		 while(noww>=0 && nowb>=0){
			 if(B && b[nowb]<=w[noww])noww--;
			 else if(B && b[nowb]>w[noww]){
				 ansb++;
				 B=false;
			 }
			 if(!B && w[noww]<=b[nowb])nowb--;
			 else if(!B && w[noww]>b[nowb]){
				 ansb++;
				 B=true;
			 }
		 }
		 
		 noww=nw-1;
		 nowb=nb-1;
		  B=false;
		 int answ=1;
		 while(noww>=0 && nowb>=0){
			 if(B && b[nowb]<=w[noww])noww--;
			 else if(B && b[nowb]>w[noww]){
				 answ++;
				 B=false;
			 }
			 if(!B && w[noww]<=b[nowb])nowb--;
			 else if(!B && w[noww]>b[nowb]){
				 answ++;
				 B=true;
			 }
		 }
		 System.out.println(Math.max(ansb,answ));
	 }


}
0