結果
| 問題 | 
                            No.2102 [Cherry Alpha *] Conditional Reflection
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-10-14 23:57:45 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,796 bytes | 
| コンパイル時間 | 2,880 ms | 
| コンパイル使用メモリ | 113,624 KB | 
| 実行使用メモリ | 109,844 KB | 
| 最終ジャッジ日時 | 2024-06-26 18:04:21 | 
| 合計ジャッジ時間 | 17,690 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 40 WA * 30 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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;
        var set = new HashSet<long>[maxlen];
        for (var i = 0; i < set.Length; ++i) set[i] = new HashSet<long>();
        var res = new bool[n];
        for (var i = 0; i < n; ++i)
        {
            var h = Hash(s[i]);
            var flg = false;
            if (set[s[i].Length - 1].Contains(h)) flg = true;
            for (var j = 0; j + 1 < s[i].Length; ++j)
            {
                if (flg) break;
                if (set[s[i].Length - 1].Contains(Swap(s[i], h, j))) flg = true;
            }
            res[i] = flg;
            set[s[i].Length - 1].Add(h);
        }
        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;
    }
}