結果

問題 No.110 しましまピラミッド
ユーザー holeguma
提出日時 2015-08-21 23:04:21
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,547 bytes
コンパイル時間 2,299 ms
コンパイル使用メモリ 78,236 KB
実行使用メモリ 52,708 KB
最終ジャッジ日時 2024-07-18 11:56:37
合計ジャッジ時間 4,259 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 3
other AC * 6 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main{

static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(in));
StringTokenizer st;
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int nw=Integer.parseInt(line);
st=new StringTokenizer(br.readLine());
int res,insertionIndex;
int[] w=new int[nw];
for(int i=0;i<nw;i++) w[i]=Integer.parseInt(st.nextToken());
int nb=Integer.parseInt(br.readLine());
st=new StringTokenizer(br.readLine());
int[] b=new int[nb];
for(int i=0;i<nb;i++) b[i]=Integer.parseInt(st.nextToken());
Arrays.sort(w);
Arrays.sort(b);
int ans1,ans2;
ans1=ans2=1;
int prev=w[nw-1];
while(true){
res=Arrays.binarySearch(b,prev);
insertionIndex=(res>=0)?res:~res;
if(insertionIndex==0||b[insertionIndex-1]==b[0]) break;
prev=b[insertionIndex-1];
ans1++;
res=Arrays.binarySearch(w,prev);
insertionIndex=(res>=0)?res:~res;
if(insertionIndex==0||w[insertionIndex-1]==w[0]) break;
prev=w[insertionIndex-1];
ans1++;
}
prev=b[nb-1];
while(true){
res=Arrays.binarySearch(w,prev);
insertionIndex=(res>=0)?res:~res;
if(insertionIndex==0||w[insertionIndex-1]==w[0]) break;
prev=w[insertionIndex-1];
ans2++;
res=Arrays.binarySearch(b,prev);
insertionIndex=(res>=0)?res:~res;
if(insertionIndex==0||b[insertionIndex-1]==b[0]) break;
prev=b[insertionIndex-1];
ans2++;
}
out.println(Math.max(ans1,ans2));
}
out.flush();
}
}
0