結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー ks2mks2m
提出日時 2021-10-29 22:53:43
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,162 bytes
コンパイル時間 2,821 ms
コンパイル使用メモリ 80,644 KB
実行使用メモリ 80,484 KB
最終ジャッジ日時 2024-04-16 15:38:48
合計ジャッジ時間 16,472 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
36,924 KB
testcase_01 AC 54 ms
37,304 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 57 ms
37,300 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 393 ms
46,676 KB
testcase_38 AC 400 ms
46,968 KB
testcase_39 AC 401 ms
47,028 KB
testcase_40 AC 399 ms
46,736 KB
testcase_41 AC 393 ms
46,896 KB
testcase_42 AC 55 ms
37,204 KB
testcase_43 AC 185 ms
63,592 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[2] && b[1] || b[1] && b[0]) {
						ret += cy[c][m] - cy[c][m - x];
						x = 0;
					} else {
						ret += cy[c][x];
					}
					x = 0;
				}
			}
		}
		ret += cx[c][x];
		return ret;
	}
}
0