結果

問題 No.345 最小チワワ問題
ユーザー nc_researchnc_research
提出日時 2021-10-04 18:29:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,472 bytes
コンパイル時間 5,144 ms
コンパイル使用メモリ 80,780 KB
実行使用メモリ 56,812 KB
最終ジャッジ日時 2023-09-30 01:01:18
合計ジャッジ時間 10,470 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,076 KB
testcase_01 AC 122 ms
56,156 KB
testcase_02 AC 120 ms
55,696 KB
testcase_03 AC 120 ms
55,696 KB
testcase_04 AC 122 ms
56,092 KB
testcase_05 AC 121 ms
56,280 KB
testcase_06 AC 120 ms
56,124 KB
testcase_07 AC 119 ms
55,868 KB
testcase_08 AC 121 ms
55,680 KB
testcase_09 AC 119 ms
55,940 KB
testcase_10 AC 120 ms
56,132 KB
testcase_11 AC 119 ms
56,032 KB
testcase_12 AC 123 ms
55,788 KB
testcase_13 AC 122 ms
56,188 KB
testcase_14 AC 125 ms
56,812 KB
testcase_15 AC 121 ms
56,100 KB
testcase_16 AC 120 ms
56,104 KB
testcase_17 AC 120 ms
55,780 KB
testcase_18 AC 120 ms
55,956 KB
testcase_19 AC 121 ms
56,084 KB
testcase_20 AC 120 ms
55,692 KB
testcase_21 AC 122 ms
56,344 KB
testcase_22 AC 121 ms
55,924 KB
testcase_23 AC 120 ms
55,944 KB
testcase_24 AC 120 ms
55,752 KB
testcase_25 AC 120 ms
56,388 KB
testcase_26 AC 120 ms
56,036 KB
testcase_27 AC 121 ms
56,448 KB
testcase_28 AC 121 ms
55,736 KB
testcase_29 AC 123 ms
56,444 KB
testcase_30 AC 123 ms
56,108 KB
testcase_31 AC 121 ms
56,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package com.mycompany.app;

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.HashMap;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class App 
{
    // strをseparatorで分割してArrayList<Integer>へ変換
    public static ArrayList<Integer> splitToArrayList(String str, String separator){
        ArrayList<Integer> ans = new ArrayList<Integer>();
        String[] separated_str = str.split(" ");
        for(int i = 0; i < separated_str.length; i++){
            ans.add(Integer.valueOf(separated_str[i]));
        }
        return ans;
    }

    public static void main( String[] args )
    {
        Scanner scan = new Scanner(System.in);
        String first_line = scan.nextLine();
        scan.close();

        // c, w, wがこの順で現れる正規表現
        Pattern p = Pattern.compile("(c.*?w.*?w)");
        Matcher m = p.matcher(first_line);

        // 文字列の最大値は100なので,デフォルト値は101
        int min_length = 101;
        int start = 0;
        while(m.find(start)){
            int matching_str_length = m.group().length();
            if(matching_str_length < min_length){
                min_length = matching_str_length;
            }
            start = m.start() + 1;
        }
        if(min_length == 101) System.out.println(-1);
        else System.out.println(min_length);
        return;

    }

}
0