結果

問題 No.2000 Distanced Characters
ユーザー tentententen
提出日時 2024-04-30 11:11:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 2,012 bytes
コンパイル時間 2,821 ms
コンパイル使用メモリ 79,548 KB
実行使用メモリ 52,556 KB
最終ジャッジ日時 2024-04-30 11:11:44
合計ジャッジ時間 5,394 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
50,348 KB
testcase_01 AC 60 ms
50,120 KB
testcase_02 AC 58 ms
50,500 KB
testcase_03 AC 59 ms
50,196 KB
testcase_04 AC 65 ms
50,156 KB
testcase_05 AC 64 ms
50,288 KB
testcase_06 AC 64 ms
50,524 KB
testcase_07 AC 65 ms
50,668 KB
testcase_08 AC 141 ms
52,332 KB
testcase_09 AC 156 ms
52,052 KB
testcase_10 AC 155 ms
52,504 KB
testcase_11 AC 135 ms
52,556 KB
testcase_12 AC 126 ms
52,304 KB
testcase_13 AC 124 ms
51,968 KB
testcase_14 AC 141 ms
52,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        char[] inputs = sc.next().toCharArray();
        int[] starts = new int[26];
        Arrays.fill(starts, -1);
        int[][] matrix = new int[26][26];
        for (int[] arr : matrix) {
            Arrays.fill(arr, Integer.MAX_VALUE);
        }
        for (int i = 0; i < inputs.length; i++) {
            int idx = inputs[i] - 'a';
            for (int j = 0; j < 26; j++) {
                if (starts[j] >= 0) {
                    matrix[j][idx] = Math.min(matrix[j][idx], i - starts[j]);
                }
            }
            starts[idx] = i;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 26; i++) {
            for (int j = 0; j < 26; j++) {
                if (j > 0) {
                    sb.append(" ");
                }
                sb.append(matrix[i][j] >= sc.nextInt() ? "Y" : "N");
            }
            sb.append("\n");
        }
        System.out.print(sb);
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0