結果
問題 | No.345 最小チワワ問題 |
ユーザー |
|
提出日時 | 2018-01-21 15:33:10 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 726 bytes |
コンパイル時間 | 3,049 ms |
コンパイル使用メモリ | 74,560 KB |
実行使用メモリ | 50,404 KB |
最終ジャッジ日時 | 2024-12-25 21:11:18 |
合計ジャッジ時間 | 5,717 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 8 WA * 21 |
ソースコード
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 = 0;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 != 0 ? ans : -1);} catch (IOException e) {e.printStackTrace();}}}