結果

問題 No.1994 Confusing Name
ユーザー 👑 kakel-sankakel-san
提出日時 2023-09-27 22:20:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,167 ms / 2,000 ms
コード長 2,724 bytes
コンパイル時間 3,200 ms
コンパイル使用メモリ 68,136 KB
実行使用メモリ 89,260 KB
最終ジャッジ日時 2023-09-27 22:20:46
合計ジャッジ時間 14,535 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
21,704 KB
testcase_01 AC 59 ms
21,624 KB
testcase_02 AC 60 ms
23,664 KB
testcase_03 AC 61 ms
23,708 KB
testcase_04 AC 62 ms
21,628 KB
testcase_05 AC 63 ms
21,580 KB
testcase_06 AC 64 ms
21,576 KB
testcase_07 AC 60 ms
21,764 KB
testcase_08 AC 64 ms
23,708 KB
testcase_09 AC 65 ms
19,692 KB
testcase_10 AC 63 ms
21,628 KB
testcase_11 AC 63 ms
21,580 KB
testcase_12 AC 553 ms
68,632 KB
testcase_13 AC 1,167 ms
82,392 KB
testcase_14 AC 614 ms
88,884 KB
testcase_15 AC 503 ms
74,632 KB
testcase_16 AC 415 ms
70,400 KB
testcase_17 AC 492 ms
76,412 KB
testcase_18 AC 641 ms
86,440 KB
testcase_19 AC 661 ms
86,676 KB
testcase_20 AC 677 ms
89,260 KB
testcase_21 AC 162 ms
39,344 KB
testcase_22 AC 93 ms
31,424 KB
testcase_23 AC 543 ms
73,680 KB
testcase_24 AC 526 ms
73,688 KB
testcase_25 AC 347 ms
55,844 KB
testcase_26 AC 188 ms
42,096 KB
testcase_27 AC 492 ms
73,584 KB
testcase_28 AC 380 ms
57,740 KB
testcase_29 AC 88 ms
27,296 KB
testcase_30 AC 413 ms
62,688 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();
        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;
                    var id = tree[s[i].Length - 1].GetId(ch);
                    if (id >= 0)
                    {
                        ++ans[i];
                        ++ans[id];
                    }
                }
                ch[j] = s[i][j];
            }
            tree[s[i].Length - 1].Insert(s[i].ToCharArray(), i);
        }
        WriteLine(string.Join("\n", ans));
        // WriteLine(string.Join(" ", ans.Take(10)));
        // WriteLine((DateTime.Now - start).TotalSeconds);
    }
    class TrieTree
    {
        class Node
        {
            public int Val;
            public Node[] Next = new Node[26];
            public Node(int val)
            {
                Val = val;
            }
        }
        Node Head = new Node('a');
        public void Insert(char[] val, int id)
        {
            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(id);
                cur = cur.Next[val[i] - 'a'];
            }
        }
        public int GetId(char[] val)
        {
            var cur = Head;
            for (var i = 0; i < val.Length; ++i)
            {
                if (cur == null) return -1;
                cur = cur.Next[val[i] - 'a'];
            }
            return cur == null ? -1 : cur.Val;
        }
    }
}
0