結果
| 問題 |
No.345 最小チワワ問題
|
| コンテスト | |
| ユーザー |
h_tyokinuhata
|
| 提出日時 | 2016-02-27 23:04:20 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 824 bytes |
| コンパイル時間 | 2,365 ms |
| コンパイル使用メモリ | 79,376 KB |
| 実行使用メモリ | 54,392 KB |
| 最終ジャッジ日時 | 2024-09-24 11:53:04 |
| 合計ジャッジ時間 | 7,335 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 12 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String S = sc.next();
char[] charS = S.toCharArray();
int i = 0, cnt = 0, flag = 0, min = Integer.MAX_VALUE;
while(i < charS.length) {
if(charS[i] == 'c') {
for(int j = i + 1; j < charS.length; j++) {
if(charS[j] == 'c') {
i = j;
}
if(charS[j] == 'w') {
cnt++;
if(cnt == 2) {
if(j - i + 1 < min) {
min = j - i + 1;
charS = S.substring(j + 1).toCharArray();
flag = 1;
}
}
}
}
}
if(flag == 1) {
i = 0;
cnt = 0;
flag = 0;
} else {
i++;
}
}
if(min == Integer.MAX_VALUE) {
System.out.println(-1);
} else {
System.out.println(min);
}
}
}
h_tyokinuhata