結果
| 問題 |
No.345 最小チワワ問題
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-11-11 14:27:28 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 117 ms / 2,000 ms |
| コード長 | 912 bytes |
| コンパイル時間 | 2,485 ms |
| コンパイル使用メモリ | 77,248 KB |
| 実行使用メモリ | 41,708 KB |
| 最終ジャッジ日時 | 2024-07-22 18:28:38 |
| 合計ジャッジ時間 | 6,773 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char[] arr = sc.next().toCharArray();
TreeSet<Integer> cPosition = new TreeSet<>();
TreeSet<Integer> wPosition = new TreeSet<>();
for (int i = 0; i < arr.length; i++) {
if (arr[i] == 'c') {
cPosition.add(i);
} else if (arr[i] == 'w') {
wPosition.add(i);
}
}
wPosition.add(Integer.MAX_VALUE - 2);
wPosition.add(Integer.MAX_VALUE - 1);
int min = Integer.MAX_VALUE;
for (int x : cPosition) {
int y = wPosition.higher(wPosition.higher(x));
min = Math.min(min, y - x + 1);
}
if (min > arr.length) {
System.out.println(-1);
} else {
System.out.println(min);
}
}
}
tenten