結果
問題 | No.1725 [Cherry 3rd Tune D] 無言の言葉 |
ユーザー | kakel-san |
提出日時 | 2021-10-29 22:54:55 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 330 ms / 4,000 ms |
コード長 | 3,304 bytes |
コンパイル時間 | 2,074 ms |
コンパイル使用メモリ | 112,268 KB |
実行使用メモリ | 62,464 KB |
最終ジャッジ日時 | 2024-10-07 12:35:20 |
合計ジャッジ時間 | 10,371 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 42 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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; } } }