結果

問題 No.1994 Confusing Name
ユーザー 👑 kakel-sankakel-san
提出日時 2023-09-27 22:15:45
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,588 bytes
コンパイル時間 2,091 ms
コンパイル使用メモリ 65,992 KB
実行使用メモリ 88,936 KB
最終ジャッジ日時 2023-09-27 22:16:08
合計ジャッジ時間 17,515 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
21,604 KB
testcase_01 AC 62 ms
21,528 KB
testcase_02 AC 63 ms
21,556 KB
testcase_03 AC 62 ms
23,584 KB
testcase_04 AC 62 ms
21,556 KB
testcase_05 AC 66 ms
21,624 KB
testcase_06 AC 69 ms
21,612 KB
testcase_07 AC 63 ms
23,592 KB
testcase_08 AC 66 ms
21,592 KB
testcase_09 AC 67 ms
21,536 KB
testcase_10 AC 66 ms
23,584 KB
testcase_11 AC 65 ms
23,592 KB
testcase_12 AC 698 ms
66,520 KB
testcase_13 TLE -
testcase_14 AC 946 ms
88,936 KB
testcase_15 AC 761 ms
76,044 KB
testcase_16 AC 636 ms
72,944 KB
testcase_17 AC 746 ms
73,796 KB
testcase_18 AC 1,000 ms
86,368 KB
testcase_19 AC 993 ms
86,716 KB
testcase_20 AC 991 ms
87,040 KB
testcase_21 AC 191 ms
37,536 KB
testcase_22 AC 108 ms
29,492 KB
testcase_23 AC 701 ms
77,252 KB
testcase_24 AC 782 ms
75,756 KB
testcase_25 AC 470 ms
58,964 KB
testcase_26 AC 252 ms
44,280 KB
testcase_27 AC 710 ms
70,104 KB
testcase_28 AC 537 ms
61,056 KB
testcase_29 AC 101 ms
29,480 KB
testcase_30 AC 578 ms
64,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var s = SList(n);
        // var r = new Random();
        // var n = 50000;
        // var s = new string[n];
        // for (var i = 0; i < n; ++i)
        // {
        //     var c = new char[10];
        //     for (var j = 0; j < 10; ++j) c[j] = (char)('a' + r.Next(26));
        //     s[i] = string.Concat(c);
        // }
        // var start = DateTime.Now;
        var tree = new TrieTree[10];
        for (var i = 0; i < tree.Length; ++i) tree[i] = new TrieTree();
        for (var i = 0; i < n; ++i) tree[s[i].Length - 1].Insert(s[i].ToCharArray());
        var ans = new int[n];
        for (var i = 0; i < n; ++i)
        {
            var ch = s[i].ToCharArray();
            for (var j = 0; j < ch.Length; ++j)
            {
                for (var c = 'a'; c <= 'z'; ++c)
                {
                    if (s[i][j] == c) continue;
                    ch[j] = c;
                    if (tree[s[i].Length - 1].Exists(ch)) ++ans[i];
                }
                ch[j] = s[i][j];
            }
        }
        WriteLine(string.Join("\n", ans));
        // WriteLine(string.Join(" ", ans.Take(10)));
        // WriteLine((DateTime.Now - start).TotalSeconds);
    }
    class TrieTree
    {
        class Node
        {
            public char Val;
            public Node[] Next = new Node[26];
            public Node(char val)
            {
                Val = val;
            }
        }
        Node Head = new Node('a');
        public void Insert(char[] val)
        {
            var cur = Head;
            for (var i = 0; i < val.Length; ++i)
            {
                if (cur.Next[val[i] - 'a'] == null) cur.Next[val[i] - 'a'] = new Node(val[i]);
                cur = cur.Next[val[i] - 'a'];
            }
        }
        public bool Exists(char[] val)
        {
            var cur = Head;
            for (var i = 0; i < val.Length; ++i)
            {
                if (cur == null) return false;
                cur = cur.Next[val[i] - 'a'];
            }
            return cur != null;
        }
    }
}
0