提出 #74105493
ソースコード 拡げる
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputReader reader = new InputReader(System.in);
PrintWriter writer = new PrintWriter(System.out, false);
int N = reader.nextInt();
int L = reader.nextInt();
int R = reader.nextInt();
String S = reader.next();
Map<Character, List<Integer>> tracks = new HashMap<>();
for (int i = 0; i < N; i++) {
tracks.computeIfAbsent(S.charAt(i), list -> new ArrayList<>()).add(i);
}
long result = 0;
for (List<Integer> indices : tracks.values()) {
for (int idx : indices) {
int lef = binarySearch(indices, idx + L);
int rig = binarySearch(indices, idx + R + 1);
result += rig - lef;
}
}
writer.println(result);
writer.close();
System.exit(0);
}
private static int binarySearch(List<Integer> indices, int K) {
int low = 0, high = indices.size();
while (low < high) {
int mid = (low + high) / 2;
if (indices.get(mid) < K) low = mid + 1;
else high = mid;
}
return low;
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
String str = "";
try {
str = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Comfortable Distance |
| ユーザ | UttamS |
| 言語 | Java24 (OpenJDK 24.0.2) |
| 得点 | 300 |
| コード長 | 2490 Byte |
| 結果 | AC |
| 実行時間 | 250 ms |
| メモリ | 69668 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 300 / 300 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | sample00.txt, sample01.txt, sample02.txt |
| All | sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| sample00.txt | AC | 58 ms | 39404 KiB |
| sample01.txt | AC | 54 ms | 39148 KiB |
| sample02.txt | AC | 55 ms | 39336 KiB |
| testcase00.txt | AC | 55 ms | 39272 KiB |
| testcase01.txt | AC | 54 ms | 39456 KiB |
| testcase02.txt | AC | 97 ms | 43256 KiB |
| testcase03.txt | AC | 190 ms | 58312 KiB |
| testcase04.txt | AC | 148 ms | 49612 KiB |
| testcase05.txt | AC | 180 ms | 52960 KiB |
| testcase06.txt | AC | 140 ms | 45192 KiB |
| testcase07.txt | AC | 221 ms | 69428 KiB |
| testcase08.txt | AC | 220 ms | 69420 KiB |
| testcase09.txt | AC | 212 ms | 69364 KiB |
| testcase10.txt | AC | 226 ms | 69300 KiB |
| testcase11.txt | AC | 212 ms | 69480 KiB |
| testcase12.txt | AC | 245 ms | 69300 KiB |
| testcase13.txt | AC | 210 ms | 68468 KiB |
| testcase14.txt | AC | 191 ms | 68300 KiB |
| testcase15.txt | AC | 198 ms | 68976 KiB |
| testcase16.txt | AC | 250 ms | 69668 KiB |
| testcase17.txt | AC | 228 ms | 69300 KiB |
| testcase18.txt | AC | 202 ms | 69180 KiB |
| testcase19.txt | AC | 242 ms | 69256 KiB |