結果
問題 | No.345 最小チワワ問題 |
ユーザー |
|
提出日時 | 2018-01-21 15:34:11 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 56 ms / 2,000 ms |
コード長 | 758 bytes |
コンパイル時間 | 3,562 ms |
コンパイル使用メモリ | 74,576 KB |
実行使用メモリ | 50,420 KB |
最終ジャッジ日時 | 2024-09-25 12:11:00 |
合計ジャッジ時間 | 6,274 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
package me.yukicoder.lv1;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class No0345 {public static void main(String[] args) {try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {char[] array = br.readLine().toCharArray();int ans = Integer.MAX_VALUE;for (int i = 0; i < array.length; i++) {if (array[i] == 'c') {// wwを探すint count = 0;for (int j = i; j < array.length; j++) {if (array[j] == 'w') {count++;}if (count == 2)ans = Math.min(ans, j - i + 1);}}}System.out.println(ans != Integer.MAX_VALUE ? ans : -1);} catch (IOException e) {e.printStackTrace();}}}