結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー jp_ste
提出日時 2016-05-12 02:14:46
言語 Java
(openjdk 23)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,288 bytes
コンパイル時間 2,268 ms
コンパイル使用メモリ 82,784 KB
実行使用メモリ 41,592 KB
最終ジャッジ日時 2024-10-13 14:01:56
合計ジャッジ時間 9,687 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    static int max = 0;
    static int n;
    
    public static void main(String[] args) {
        try (Scanner scan = new Scanner(System.in)) {
            n = Integer.parseInt(scan.next());
            String str = scan.next() + scan.next();
            solve(str);
            solve(new StringBuffer(str).reverse().toString());
            System.out.println(max);
        }
    }
    
    static void solve(String str) {
        
        int count = 0;
        for(int i=0; i<str.length(); i++) {
            if(str.charAt(i) == 'o') {
                count++;
            } else {
                break;
            }
        }
        max = Math.max(max, count+n);
        
        count = 0;
        for(int i=str.length()-1; i>=0; i--) {
            if(str.charAt(i) == 'o') {
                count++;
            } else {
                break;
            }
        }
        max = Math.max(max, count+n);
        
        for(int i=0; i<str.length(); i++) {
            if(str.charAt(i) == 'o') {
                int count1 = 0;
                int j;
                for(j=i; j<str.length(); j++) {
                    if(str.charAt(j) == 'o') {
                        count1++;
                    } else {
                        break;
                    }
                }
                
                int count2 = 0;
                int k;
                for(k=j; k<str.length(); k++) {
                    if(str.charAt(k) == 'x') {
                        count2++;
                    } else {
                        break;
                    }
                }
                             
                if(count2 > n) { 
                    count2 = n;
                    max = Math.max(max, count1+count2);
                    
                } else {
                
                    int count3 = 0;
                    int l;
                    for(l=k; l<str.length(); l++) {
                        if(str.charAt(l) == 'o') {
                            count3++;
                        } else {
                            break;
                        }
                    }
                    max = Math.max(max, count1+count2+count3);
                }
            }
        }
    }
}
0