結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー 👑 kakel-sankakel-san
提出日時 2021-10-29 22:54:55
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 328 ms / 4,000 ms
コード長 3,304 bytes
コンパイル時間 2,774 ms
コンパイル使用メモリ 111,008 KB
実行使用メモリ 70,436 KB
最終ジャッジ日時 2024-04-16 15:39:30
合計ジャッジ時間 11,056 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
25,264 KB
testcase_01 AC 30 ms
25,136 KB
testcase_02 AC 30 ms
25,336 KB
testcase_03 AC 33 ms
25,336 KB
testcase_04 AC 31 ms
25,136 KB
testcase_05 AC 32 ms
27,256 KB
testcase_06 AC 42 ms
25,000 KB
testcase_07 AC 35 ms
27,540 KB
testcase_08 AC 37 ms
25,724 KB
testcase_09 AC 31 ms
25,136 KB
testcase_10 AC 34 ms
25,076 KB
testcase_11 AC 30 ms
25,336 KB
testcase_12 AC 44 ms
30,124 KB
testcase_13 AC 44 ms
28,024 KB
testcase_14 AC 129 ms
30,480 KB
testcase_15 AC 47 ms
28,524 KB
testcase_16 AC 53 ms
28,660 KB
testcase_17 AC 69 ms
31,272 KB
testcase_18 AC 149 ms
32,884 KB
testcase_19 AC 64 ms
29,408 KB
testcase_20 AC 44 ms
26,360 KB
testcase_21 AC 144 ms
31,608 KB
testcase_22 AC 200 ms
46,292 KB
testcase_23 AC 202 ms
44,736 KB
testcase_24 AC 147 ms
40,544 KB
testcase_25 AC 225 ms
53,648 KB
testcase_26 AC 190 ms
48,680 KB
testcase_27 AC 183 ms
56,356 KB
testcase_28 AC 252 ms
51,736 KB
testcase_29 AC 245 ms
52,428 KB
testcase_30 AC 226 ms
58,844 KB
testcase_31 AC 158 ms
42,140 KB
testcase_32 AC 274 ms
69,376 KB
testcase_33 AC 282 ms
70,436 KB
testcase_34 AC 270 ms
63,204 KB
testcase_35 AC 266 ms
61,320 KB
testcase_36 AC 277 ms
66,780 KB
testcase_37 AC 327 ms
29,904 KB
testcase_38 AC 328 ms
30,028 KB
testcase_39 AC 327 ms
31,948 KB
testcase_40 AC 328 ms
30,292 KB
testcase_41 AC 324 ms
27,852 KB
testcase_42 AC 30 ms
25,232 KB
testcase_43 AC 110 ms
68,636 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;

class yuki320
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static void Main()
    {
        var x = ReadLine();
        var y = ReadLine();
        var q = NN;
        var l = new int[q];
        var r = new int[q];
        var c = new char[q];
        for (var i = 0; i < q; ++i)
        {
            var cin = ReadLine().Split();
            l[i] = int.Parse(cin[0]) - 1;
            r[i] = int.Parse(cin[1]);
            c[i] = cin[2][0];
        }
        var rmax = r.Max();

        xcum = new int[26][];
        ycum = new int[26][];
        xrcum = new int[26][];
        yrcum = new int[26][];
        xl = x.Length;
        yl = y.Length;
        for (var i = 0; i < xcum.Length; ++i)
        {
            xcum[i] = new int[x.Length + 1];
            ycum[i] = new int[y.Length + 1];
            xrcum[i] = new int[x.Length + 1];
            yrcum[i] = new int[y.Length + 1];
        }
        for (var j = 0; j < x.Length; ++j)
        {
            for (var i = 0; i < 26; ++i)
            {
                xcum[i][j + 1] = xcum[i][j];
                xrcum[i][j + 1] = xrcum[i][j];
            }
            ++xcum[x[j] - 'a'][j + 1];
            ++xrcum[x[x.Length - j - 1] - 'a'][j + 1];
        }
        for (var j = 0; j < y.Length; ++j)
        {
            for (var i = 0; i < 26; ++i)
            {
                ycum[i][j + 1] = ycum[i][j];
                yrcum[i][j + 1] = yrcum[i][j];
            }
            ++ycum[y[j] - 'a'][j + 1];
            ++yrcum[y[y.Length - j - 1] - 'a'][j + 1];
        }
        lenlist = new List<int>();
        lenlist.Add(x.Length);
        while (lenlist.Last() < rmax) lenlist.Add(lenlist.Last() * 2 + y.Length);

        var res = new int[q];
        for (var i = 0; i < q; ++i)
            res[i] = DFS(r[i], lenlist.Count, c[i] - 'a', false) - DFS(l[i], lenlist.Count, c[i] - 'a', false);
        WriteLine(string.Join("\n", res));
    }
    static List<int> lenlist;
    static int[][] xcum;
    static int[][] xrcum;
    static int[][] ycum;
    static int[][] yrcum;
    static int xl;
    static int yl;
    static int DFS(int cur, int depth, int ch, bool rev)
    {
        if (depth == 0)
        {
            if (rev) return xrcum[ch][cur];
            else return xcum[ch][cur];
        }
        else if (cur < lenlist[depth - 1]) return DFS(cur, depth - 1, ch, false);
        else if (cur < lenlist[depth - 1] + yl)
        {
            var res = xcum[ch].Last() * (int)Math.Pow(2, depth - 1);
            res += ycum[ch].Last() * ((int)Math.Pow(2, depth - 1) - 1);
            if (rev) res += yrcum[ch][cur - lenlist[depth - 1]];
            else res += ycum[ch][cur - lenlist[depth - 1]];
            return res;
        }
        else
        {
            var res = xcum[ch].Last() * (int)Math.Pow(2, depth - 1);
            res += ycum[ch].Last() * ((int)Math.Pow(2, depth - 1) - 1);
            res += yrcum[ch].Last();
            res += DFS(cur - lenlist[depth - 1] - yl, depth - 1, ch, true);
            return res;
        }
    }
}
0