結果

問題 No.2226 Hello, Forgotten World!
ユーザー tentententen
提出日時 2023-02-28 10:44:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 2,666 bytes
コンパイル時間 2,994 ms
コンパイル使用メモリ 93,996 KB
実行使用メモリ 58,208 KB
最終ジャッジ日時 2023-10-13 17:20:28
合計ジャッジ時間 5,002 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,680 KB
testcase_01 AC 219 ms
58,208 KB
testcase_02 AC 118 ms
55,476 KB
testcase_03 AC 117 ms
54,764 KB
testcase_04 AC 64 ms
51,704 KB
testcase_05 AC 123 ms
55,256 KB
testcase_06 AC 94 ms
53,616 KB
testcase_07 AC 107 ms
53,112 KB
testcase_08 AC 60 ms
50,952 KB
testcase_09 AC 105 ms
54,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int t = sc.nextInt();
        char[] hellow = "helloworld".toCharArray();
        StringBuilder sb = new StringBuilder();
        while (t-- > 0) {
            int n = sc.nextInt();
            String s = sc.next();
            ArrayList<String> ans = new ArrayList<>();
            for (int i = 0; i <= n - hellow.length; i++) {
                boolean enable = true;
                for (int j = 0; j < hellow.length && enable; j++) {
                    enable = (s.charAt(i + j) == hellow[j] || s.charAt(i + j) == '?');
                }
                if (!enable) {
                    continue;
                }
                char[] target = s.toCharArray();
                for (int j = 0; j < 10; j++) {
                    target[i + j] = hellow[j];
                }
                for (int j = 0; j < n; j++) {
                    if (target[j] == '?') {
                        target[j] = 'a';
                    }
                }
                ans.add(new String(target));
            }
            Collections.sort(ans);
            if (ans.size() == 0) {
                sb.append("-1\n");
            } else {
                sb.append(ans.get(0)).append("\n");
            }
        }
        System.out.print(sb);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0