結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー Democo
提出日時 2015-05-17 18:36:38
言語 Java
(openjdk 23)
結果
AC  
実行時間 143 ms / 1,000 ms
コード長 981 bytes
コンパイル時間 2,427 ms
コンパイル使用メモリ 78,988 KB
実行使用メモリ 42,088 KB
最終ジャッジ日時 2024-12-24 11:46:20
合計ジャッジ時間 10,720 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
class Yukico204 {
	public static void main(String[] args) {
		Scanner stdio = new Scanner(System.in);
		int d = stdio.nextInt();
		String s = stdio.next();
		s += stdio.next();
		s = "xxxxxxxxxxxxxx"+s+"xxxxxxxxxxxxxx";
		int ans = d;
		int cnt=0;
		for(int i=0; i<s.length(); i++) {
			if(s.charAt(i) == 'o') {
				cnt++;
				ans = Math.max(ans, cnt);
			} else {
				cnt = 0;
			}
		}
		if(d==0) {
			System.out.println(ans);
		} else {
			cnt = 0;
			for(int i=0; i<s.length(); i++) {
				cnt = 0;
				boolean b=true;
				for(int j=0; j<s.length(); j++) {
					if((j-i)>=0 && (j-i)<d && b) {
						if(s.charAt(j) == 'o') {
							cnt++;
							ans = Math.max(ans, cnt);
							b = false;
						} else {
							cnt++;
							ans = Math.max(ans, cnt);
						}
					} else if(s.charAt(j) == 'o') {
						cnt++;
						ans = Math.max(ans, cnt);
					}
					else {
						cnt = 0;
					}
				}
				ans = Math.max(ans, cnt);
			}
			System.out.println(ans);
		}
	}
}
0