結果

問題 No.345 最小チワワ問題
ユーザー nc_researchnc_research
提出日時 2021-10-04 18:09:53
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,413 bytes
コンパイル時間 4,873 ms
コンパイル使用メモリ 77,912 KB
実行使用メモリ 57,188 KB
最終ジャッジ日時 2023-09-30 00:39:17
合計ジャッジ時間 9,013 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,996 KB
testcase_01 WA -
testcase_02 AC 115 ms
55,332 KB
testcase_03 AC 118 ms
56,096 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 117 ms
56,064 KB
testcase_08 AC 118 ms
55,852 KB
testcase_09 AC 118 ms
56,372 KB
testcase_10 AC 118 ms
55,692 KB
testcase_11 AC 117 ms
54,680 KB
testcase_12 AC 116 ms
55,780 KB
testcase_13 AC 117 ms
55,804 KB
testcase_14 AC 117 ms
56,048 KB
testcase_15 WA -
testcase_16 AC 118 ms
56,084 KB
testcase_17 AC 122 ms
55,296 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 116 ms
55,956 KB
testcase_21 AC 116 ms
55,672 KB
testcase_22 AC 117 ms
56,008 KB
testcase_23 AC 116 ms
56,176 KB
testcase_24 AC 117 ms
55,644 KB
testcase_25 AC 119 ms
55,688 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 117 ms
55,580 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 118 ms
55,716 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[^c]*w[^w]*w)");
        Matcher m = p.matcher(first_line);

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

    }

}
0