結果
問題 |
No.345 最小チワワ問題
|
ユーザー |
|
提出日時 | 2023-11-24 22:59:09 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 137 ms / 2,000 ms |
コード長 | 1,741 bytes |
コンパイル時間 | 2,749 ms |
コンパイル使用メモリ | 77,852 KB |
実行使用メモリ | 41,528 KB |
最終ジャッジ日時 | 2024-09-26 09:45:03 |
合計ジャッジ時間 | 7,784 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static class Pair { public Integer status; public Integer length; public Pair(Integer s, Integer l) { this.status = s; this.length = l; } } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String a = scanner.next(); String[] strArray = a.split(""); List<Pair> pairList = new ArrayList<Pair>(); for (String s : strArray) { if (s.equals("c")) { for (Pair p : pairList) { if (p.status == 2) { continue; } p.length++; } Pair pair = new Pair(0, 1); pairList.add(pair); } else if (s.equals("w")) { for (Pair p : pairList) { if (p.status == 2) { continue; } p.status++; p.length++; } } else { for (Pair p : pairList) { if (p.status == 2) { continue; } p.length++; } } } int minLength = 101; for (Pair p : pairList) { if (p.status == 2) { if (p.length < minLength) { minLength = p.length; } } } if (minLength == 101) { System.out.println(-1); } else { System.out.println(minLength); } } }