結果

問題 No.110 しましまピラミッド
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-15 01:24:44
言語 Java21
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 6,710 bytes
コンパイル時間 2,716 ms
コンパイル使用メモリ 74,048 KB
実行使用メモリ 57,892 KB
最終ジャッジ日時 2023-09-17 20:20:14
合計ジャッジ時間 7,861 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,992 KB
testcase_01 AC 124 ms
54,192 KB
testcase_02 AC 124 ms
55,392 KB
testcase_03 AC 124 ms
55,856 KB
testcase_04 AC 123 ms
56,196 KB
testcase_05 AC 124 ms
55,756 KB
testcase_06 AC 125 ms
55,920 KB
testcase_07 AC 126 ms
55,824 KB
testcase_08 AC 125 ms
56,040 KB
testcase_09 AC 125 ms
55,744 KB
testcase_10 AC 125 ms
55,964 KB
testcase_11 AC 125 ms
55,788 KB
testcase_12 AC 124 ms
55,804 KB
testcase_13 AC 124 ms
55,860 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 125 ms
55,832 KB
testcase_20 AC 123 ms
55,916 KB
testcase_21 AC 126 ms
55,708 KB
testcase_22 AC 124 ms
55,876 KB
testcase_23 AC 124 ms
55,448 KB
testcase_24 AC 126 ms
55,748 KB
testcase_25 AC 125 ms
55,956 KB
testcase_26 AC 123 ms
56,224 KB
testcase_27 AC 125 ms
55,968 KB
testcase_28 AC 124 ms
56,052 KB
testcase_29 AC 126 ms
55,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        int nw = koko.nextInt();
        int[] ww = new int[nw];
        for(int i=0; i<nw; i++){
            ww[i] = koko.nextInt();
        }
        int nb = koko.nextInt();
        int[] wb = new int[nb];
        for(int i=0; i<nb; i++){
            wb[i] = koko.nextInt();
        }
        Arrays.sort(ww);
        int[] w = new int[nw];
        for(int i=0; i<nw; i++){
            w[i]=ww[nw-1-i];
        }
        Arrays.sort(wb);
        int[] b = new int[nb];
        for(int i=0; i<nb; i++){
            b[i]=wb[nb-1-i];
        }
        char color = 'N';
        int count=0;
        int countb=0;
        int countw=0;
        int now=0;
        if(w[0]>b[0]){
            count=1;
            countw=0;
            now=w[0];
            color='W';
            while(countb!=nb-1||countw!=nw-1){
                if(color=='W'){
                    if(b[nb-1]>=now){
                        break;
                    }
                    for(int i=countb; i<nb; i++){
                        if(b[i]<now){
                            count=count+1;
                            countb=i+1;
                            now=b[i];
                            color='B';
                            break;
                        }
                    }
                }else if(color=='B'){
                    if(w[nw-1]>=now){
                        break;
                    }
                    for(int i=countw; i<nw; i++){
                        if(w[i]<now){
                            count=count+1;
                            countw=i+1;
                            now=w[i];
                            color='W';
                            break;
                        }
                    }
                }
            }
        }else if(w[0]<b[0]){
            count=1;
            countb=0;
            now=b[0];
            color='B';
            while(countb!=nb||countw!=nw){
                if(color=='W'){
                    if(b[nb-1]>=now){
                        break;
                    }
                    for(int i=countb; i<nb; i++){
                        if(b[i]<now){
                            count=count+1;
                            countb=i+1;
                            now=b[i];
                            color='B';
                            break;
                        }
                    }
                }else if(color=='B'){
                    if(w[nw-1]>=now){
                        break;
                    }
                    for(int i=countw; i<nw; i++){
                        if(w[i]<now){
                            count=count+1;
                            countw=i+1;
                            now=w[i];
                            color='W';
                            break;
                        }
                    }
                }
            }
        }else if(w[0]==b[0]){
            count=1;
            now=w[0];
            if(nb>1&&nw>1){
                for(int i=1; i<Math.min(nb,nw); i++){
                    if(w[i]==b[i]){
                        if(w[i]<now){
                            count=count+1;
                            now=w[i];
                            countb=i+1;
                            countw=i+1;
                            color='W';
                        }
                    }else if(w[i]>b[i]){
                        if(w[i]<now){
                            count=count+1;
                            now=w[i];
                            countw=i+1;
                            countb=i;
                            color='W';
                            break;
                        }else if(b[i]<now){
                            count=count+1;
                            now=b[i];
                            countw=i+1;
                            countb=i+1;
                            color='B';
                            break;
                        }
                    }else if(w[i]<b[i]){
                        if(b[i]<now){
                            count=count+1;
                            now=b[i];
                            countb=i+1;
                            countw=i;
                            color='B';
                            break;
                        }else if(w[i]<now){
                            count=count+1;
                            now=w[i];
                            countw=i+1;
                            countb=i+1;
                            color='W';
                            break;
                        }
                    }else if(i==Math.min(nb,nw)-1){
                        if(nb>nw){
                            now=w[i];
                            countw=nw;
                            countb=nw-1;
                            color='W';
                        }else if(nw>nb){
                            now=b[i];
                            countw=nb-1;
                            countb=nb;
                            color='B';
                        }else if(nw==nb){
                            countw=nw;
                            countb=nb;
                        }
                    }
                }
            }else if(nb==1){
                count=1;
                countb=nb-1;
                now=b[0];
                countw=0;
                color='B';
            }else if(nw==1){
                count=1;
                countb=0;
                countw=nw-1;
                now=w[0];
                color='W';
            }
            while(countb!=nb||countw!=nw){
                if(color=='W'){
                    if(b[nb-1]>=now){
                        break;
                    }
                    for(int i=countb; i<nb; i++){
                        if(b[i]<now){
                            count=count+1;
                            countb=i+1;
                            now=b[i];
                            color='B';
                            break;
                        }
                    }
                }else if(color=='B'){
                    if(w[nw-1]>=now){
                        break;
                    }
                    for(int i=countw; i<nw; i++){
                        if(w[i]<now){
                            count=count+1;
                            countw=i+1;
                            now=w[i];
                            color='W';
                            break;
                        }
                    }
                }
            }
        }
        System.out.println(count);
    }
}
0