結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー 👑 kakel-sankakel-san
提出日時 2022-10-15 00:22:37
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 753 ms / 3,000 ms
コード長 2,960 bytes
コンパイル時間 2,313 ms
コンパイル使用メモリ 64,156 KB
実行使用メモリ 220,084 KB
最終ジャッジ日時 2023-09-09 01:12:43
合計ジャッジ時間 24,524 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
21,600 KB
testcase_01 AC 54 ms
21,544 KB
testcase_02 AC 202 ms
43,212 KB
testcase_03 AC 227 ms
43,368 KB
testcase_04 AC 202 ms
43,324 KB
testcase_05 AC 159 ms
40,244 KB
testcase_06 AC 208 ms
45,772 KB
testcase_07 AC 213 ms
37,500 KB
testcase_08 AC 100 ms
26,400 KB
testcase_09 AC 218 ms
42,260 KB
testcase_10 AC 124 ms
32,656 KB
testcase_11 AC 114 ms
33,488 KB
testcase_12 AC 178 ms
42,308 KB
testcase_13 AC 251 ms
49,448 KB
testcase_14 AC 177 ms
43,792 KB
testcase_15 AC 226 ms
46,864 KB
testcase_16 AC 279 ms
55,824 KB
testcase_17 AC 155 ms
30,628 KB
testcase_18 AC 233 ms
41,676 KB
testcase_19 AC 140 ms
34,464 KB
testcase_20 AC 272 ms
54,064 KB
testcase_21 AC 146 ms
35,044 KB
testcase_22 AC 328 ms
53,016 KB
testcase_23 AC 313 ms
55,568 KB
testcase_24 AC 314 ms
57,464 KB
testcase_25 AC 318 ms
57,704 KB
testcase_26 AC 320 ms
57,796 KB
testcase_27 AC 317 ms
55,192 KB
testcase_28 AC 322 ms
55,216 KB
testcase_29 AC 321 ms
57,536 KB
testcase_30 AC 324 ms
57,404 KB
testcase_31 AC 321 ms
57,184 KB
testcase_32 AC 319 ms
57,308 KB
testcase_33 AC 319 ms
57,220 KB
testcase_34 AC 326 ms
55,696 KB
testcase_35 AC 321 ms
55,072 KB
testcase_36 AC 313 ms
53,460 KB
testcase_37 AC 314 ms
59,800 KB
testcase_38 AC 315 ms
57,500 KB
testcase_39 AC 317 ms
57,220 KB
testcase_40 AC 312 ms
59,180 KB
testcase_41 AC 319 ms
55,872 KB
testcase_42 AC 261 ms
42,176 KB
testcase_43 AC 257 ms
44,072 KB
testcase_44 AC 257 ms
44,676 KB
testcase_45 AC 264 ms
44,008 KB
testcase_46 AC 262 ms
40,652 KB
testcase_47 AC 233 ms
32,344 KB
testcase_48 AC 248 ms
32,368 KB
testcase_49 AC 230 ms
32,228 KB
testcase_50 AC 231 ms
32,124 KB
testcase_51 AC 233 ms
34,244 KB
testcase_52 AC 753 ms
219,804 KB
testcase_53 AC 747 ms
219,708 KB
testcase_54 AC 720 ms
220,084 KB
testcase_55 AC 195 ms
25,548 KB
testcase_56 AC 196 ms
27,556 KB
testcase_57 AC 198 ms
31,596 KB
testcase_58 AC 447 ms
127,784 KB
testcase_59 AC 319 ms
62,832 KB
testcase_60 AC 106 ms
28,004 KB
testcase_61 AC 198 ms
25,492 KB
testcase_62 AC 62 ms
24,152 KB
testcase_63 AC 110 ms
26,520 KB
testcase_64 AC 107 ms
24,520 KB
testcase_65 AC 110 ms
24,592 KB
testcase_66 AC 190 ms
27,660 KB
testcase_67 AC 164 ms
36,124 KB
testcase_68 AC 184 ms
29,584 KB
testcase_69 AC 168 ms
34,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Program
{
    static int NN => int.Parse(ReadLine());
    static string[] SList(int n) => Enumerable.Repeat(0, n).Select(_ => ReadLine()).ToArray();
    static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var s = SList(n);
        WriteLine(Ref(n, s));
    }
    static string Ref(int n, string[] s)
    {
        var maxlen = s.Max(si => si.Length);
        mul = new long[maxlen];
        mul[0] = 1;
        for (var i = 1; i < mul.Length; ++i) mul[i] = mul[i - 1] * 31 % mod;
        mul2 = new long[maxlen];
        mul2[0] = 2;
        for (var i = 1; i < mul2.Length; ++i) mul2[i] = mul2[i - 1] * 41 % mod2;
        var set = new Dictionary<long, string>[maxlen];
        for (var i = 0; i < set.Length; ++i) set[i] = new Dictionary<long, string>();
        var set2 = new Dictionary<long, string>[maxlen];
        for (var i = 0; i < set2.Length; ++i) set2[i] = new Dictionary<long, string>();
        var res = new bool[n];
        for (var i = 0; i < n; ++i)
        {
            var h = Hash(s[i]);
            var h2 = Hash2(s[i]);
            var flg = false;
            var len = s[i].Length - 1;
            if (set[len].ContainsKey(h) && set2[len].ContainsKey(h2))
            {
                if (set[len][h] == set2[len][h2]) flg = true;
            }
            for (var j = 0; j + 1 < s[i].Length; ++j)
            {
                if (flg) break;
                var sw1 = Swap(s[i], h, j);
                var sw2 = Swap2(s[i], h2, j);
                if (set[len].ContainsKey(sw1) && set2[len].ContainsKey(sw2))
                {
                    if (set[len][sw1] == set2[len][sw2]) flg = true;
                }
            }
            res[i] = flg;
            set[len][h] = s[i];
            set2[len][h2] = s[i];
        }
        return string.Join("\n", res.Select(f => f ? "Yes" : "No"));
    }
    static int mod = 1_000_000_009;
    static long[] mul = new long[0];
    static long Hash(string a)
    {
        var res = 0L;
        for (var i = 0; i < a.Length; ++i) res = (res + (a[i] - 'a') * mul[i]) % mod;
        return res;
    }
    static long Swap(string a, long hash, int pos)
    {
        return (hash + (a[pos + 1] - a[pos] + mod) * mul[pos] % mod + (a[pos] - a[pos + 1] + mod) * mul[pos + 1] % mod) % mod;
    }
    static int mod2 = 1_110_000_019;
    static long[] mul2 = new long[0];
    static long Hash2(string a)
    {
        var res = 0L;
        for (var i = 0; i < a.Length; ++i) res = (res + (a[i] - 'a') * mul2[i]) % mod2;
        return res;
    }
    static long Swap2(string a, long hash, int pos)
    {
        return (hash + (a[pos + 1] - a[pos] + mod2) * mul2[pos] % mod2 + (a[pos] - a[pos + 1] + mod2) * mul2[pos + 1] % mod2) % mod2;
    }
}
0