結果
問題 | No.345 最小チワワ問題 |
ユーザー | YOSHI |
提出日時 | 2021-03-12 21:47:52 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 49 ms / 2,000 ms |
コード長 | 679 bytes |
コンパイル時間 | 2,911 ms |
コンパイル使用メモリ | 73,208 KB |
実行使用メモリ | 37,172 KB |
最終ジャッジ日時 | 2024-10-14 12:06:57 |
合計ジャッジ時間 | 5,449 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class No00000345_Main { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String s = br.readLine(); int minLen = 101; for(int i = 0; i < s.length(); i++) { char c = s.charAt(i); if(c == 'c') { int wCnt = 0; for(int j = i; j < s.length(); j++) { char cSub = s.charAt(j); if(cSub == 'w') wCnt++; if(wCnt == 2 && j - i + 1 < minLen) { minLen = j - i + 1; break; } } } } System.out.println( minLen == 101 ? -1 : minLen); } }