結果

問題 No.110 しましまピラミッド
ユーザー リチウム
提出日時 2014-12-23 23:44:20
言語 Java
(openjdk 23)
結果
AC  
実行時間 153 ms / 5,000 ms
コード長 1,069 bytes
コンパイル時間 4,053 ms
コンパイル使用メモリ 78,400 KB
実行使用メモリ 55,928 KB
最終ジャッジ日時 2024-12-31 11:03:18
合計ジャッジ時間 9,313 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

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