結果

問題 No.345 最小チワワ問題
ユーザー キョウチクキョウチク
提出日時 2022-05-17 22:28:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 864 bytes
コンパイル時間 6,433 ms
コンパイル使用メモリ 74,700 KB
実行使用メモリ 56,152 KB
最終ジャッジ日時 2023-10-14 00:45:26
合計ジャッジ時間 11,645 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,756 KB
testcase_01 AC 123 ms
56,088 KB
testcase_02 AC 123 ms
55,912 KB
testcase_03 AC 124 ms
55,780 KB
testcase_04 AC 124 ms
55,544 KB
testcase_05 AC 124 ms
55,576 KB
testcase_06 AC 124 ms
55,964 KB
testcase_07 AC 123 ms
55,944 KB
testcase_08 AC 122 ms
55,892 KB
testcase_09 AC 122 ms
55,916 KB
testcase_10 AC 123 ms
55,784 KB
testcase_11 AC 123 ms
55,532 KB
testcase_12 AC 122 ms
55,784 KB
testcase_13 AC 125 ms
55,864 KB
testcase_14 AC 128 ms
55,380 KB
testcase_15 AC 124 ms
56,060 KB
testcase_16 AC 123 ms
55,832 KB
testcase_17 AC 125 ms
55,740 KB
testcase_18 AC 124 ms
55,676 KB
testcase_19 AC 123 ms
56,152 KB
testcase_20 AC 124 ms
55,676 KB
testcase_21 AC 125 ms
55,616 KB
testcase_22 AC 124 ms
55,764 KB
testcase_23 AC 126 ms
55,712 KB
testcase_24 AC 123 ms
55,812 KB
testcase_25 AC 122 ms
53,872 KB
testcase_26 AC 124 ms
55,604 KB
testcase_27 AC 123 ms
55,372 KB
testcase_28 AC 122 ms
55,624 KB
testcase_29 AC 122 ms
55,380 KB
testcase_30 AC 123 ms
55,748 KB
testcase_31 AC 122 ms
55,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Test11 {
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String line;
    line=sc.nextLine();
    int n=line.length();
    ArrayList<Integer> c_=new ArrayList<>(),w_=new ArrayList<>();
    for(int i=0;i<n;i++){
      switch(line.charAt(i)){
      case 'c':
        c_.add(i);
        break;
      case 'w':
        w_.add(i);
        break;
      }
    }
    int min=Integer.MAX_VALUE;
    for(int i=0;i<c_.size();i++){
      int tmp=c_.get(i),tmp1=Integer.MAX_VALUE;
      int i1;
      for(i1=1;i1<w_.size();i1++){
        int tmp2=w_.get(i1-1);
        if(tmp<tmp2){
          tmp1=w_.get(i1)-tmp+1;
          break;
        }
      }
      if(tmp1<min) min=tmp1;
      if(i1==w_.size()) break;
    }
    if(min==Integer.MAX_VALUE) min=-1;
    System.out.println(min);
    sc.close();
  }
}
0