結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー ks2mks2m
提出日時 2021-10-29 23:10:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 606 ms / 4,000 ms
コード長 2,142 bytes
コンパイル時間 2,788 ms
コンパイル使用メモリ 78,704 KB
実行使用メモリ 72,408 KB
最終ジャッジ日時 2024-04-16 15:48:55
合計ジャッジ時間 16,764 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
37,264 KB
testcase_01 AC 51 ms
37,120 KB
testcase_02 AC 69 ms
37,728 KB
testcase_03 AC 120 ms
39,652 KB
testcase_04 AC 59 ms
37,400 KB
testcase_05 AC 70 ms
37,660 KB
testcase_06 AC 167 ms
41,984 KB
testcase_07 AC 126 ms
40,420 KB
testcase_08 AC 159 ms
41,460 KB
testcase_09 AC 58 ms
37,452 KB
testcase_10 AC 118 ms
40,244 KB
testcase_11 AC 56 ms
37,160 KB
testcase_12 AC 175 ms
43,320 KB
testcase_13 AC 179 ms
43,520 KB
testcase_14 AC 343 ms
47,496 KB
testcase_15 AC 186 ms
46,236 KB
testcase_16 AC 205 ms
46,224 KB
testcase_17 AC 245 ms
48,332 KB
testcase_18 AC 365 ms
47,688 KB
testcase_19 AC 217 ms
44,204 KB
testcase_20 AC 179 ms
42,744 KB
testcase_21 AC 347 ms
47,320 KB
testcase_22 AC 388 ms
54,176 KB
testcase_23 AC 383 ms
53,860 KB
testcase_24 AC 317 ms
49,676 KB
testcase_25 AC 478 ms
63,156 KB
testcase_26 AC 390 ms
55,340 KB
testcase_27 AC 396 ms
59,364 KB
testcase_28 AC 457 ms
61,252 KB
testcase_29 AC 463 ms
60,040 KB
testcase_30 AC 429 ms
63,760 KB
testcase_31 AC 342 ms
51,916 KB
testcase_32 AC 518 ms
68,536 KB
testcase_33 AC 606 ms
72,408 KB
testcase_34 AC 562 ms
67,804 KB
testcase_35 AC 487 ms
65,864 KB
testcase_36 AC 561 ms
67,904 KB
testcase_37 AC 381 ms
46,916 KB
testcase_38 AC 384 ms
46,712 KB
testcase_39 AC 397 ms
46,656 KB
testcase_40 AC 394 ms
46,664 KB
testcase_41 AC 406 ms
46,332 KB
testcase_42 AC 52 ms
37,468 KB
testcase_43 AC 154 ms
62,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class Main {
	static int n, m;
	static int[][] cx, cy;
	static List<Integer> list;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] x = br.readLine().toCharArray();
		char[] y = br.readLine().toCharArray();
		int q = Integer.parseInt(br.readLine());
		int[] l = new int[q];
		int[] r = new int[q];
		int[] c = new int[q];
		for (int i = 0; i < q; i++) {
			String[] sa = br.readLine().split(" ");
			l[i] = Integer.parseInt(sa[0]) - 1;
			r[i] = Integer.parseInt(sa[1]);
			c[i] = sa[2].charAt(0) - 'a';
		}
		br.close();

		n = x.length;
		cx = new int[26][n + 1];
		for (int i = 0; i < n; i++) {
			cx[x[i] - 'a'][i + 1]++;
			for (int j = 0; j < 26; j++) {
				cx[j][i + 1] += cx[j][i];
			}
		}

		m = y.length;
		cy = new int[26][m + 1];
		for (int i = 0; i < m; i++) {
			cy[y[i] - 'a'][i + 1]++;
			for (int j = 0; j < 26; j++) {
				cy[j][i + 1] += cy[j][i];
			}
		}

		list = new ArrayList<>();
		list.add(n);
		while (true) {
			int cur = list.get(list.size() - 1);
			int next = cur * 2 + m;
			list.add(next);
			if (next > 1000000000) {
				break;
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			int ans = f(r[i], c[i]) - f(l[i], c[i]);
			pw.println(ans);
		}
		pw.flush();
	}

	static int f(int x, int c) {
		int ret = 0;
		boolean[] b = new boolean[40];
		for (int i = list.size() - 1; i >= 0 && x > 0; i--) {
			int len = list.get(i);
			if (x >= len) {
				b[i] = true;
				int v1 = cx[c][n];
				int v2 = 1 << i;
				ret += v1 * v2;
				int v3 = cy[c][m];
				int v4 = v2 - 1;
				ret += v3 * v4;
				x -= len;
				if (x >= m) {
					ret += v3;
					x -= m;
					if (i == 0) {
						ret += cx[c][n] - cx[c][n - x];
						x = 0;
					}
				} else {
					if (b[i + 1]) {
						ret += cy[c][m] - cy[c][m - x];
						x = 0;
					} else {
						ret += cy[c][x];
					}
					x = 0;
				}
			}
		}
		ret += cx[c][x];
		return ret;
	}
}
0