結果

問題 No.2715 Unique Chimatagram
ユーザー kakel-san
提出日時 2024-04-05 22:13:20
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 2,236 bytes
コンパイル時間 9,724 ms
コンパイル使用メモリ 169,104 KB
実行使用メモリ 194,676 KB
最終ジャッジ日時 2024-10-01 02:28:35
合計ジャッジ時間 13,540 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (100 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

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 int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).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 ans = Chimata(n, s);
        WriteLine(ans);
    }
    static string Chimata(int n, string[] s)
    {
        var dic = new Dictionary<Data, List<int>>();
        for (var i = 0; i < n; ++i)
        {
            var counts = new int[26];
            foreach (var c in s[i]) ++counts[c - 'a'];
            for (var c = 0; c < 26; ++c)
            {
                ++counts[c];
                var data = new Data(counts);
                if (dic.ContainsKey(data)) dic[data].Add(i);
                else dic[data] = new List<int>{ i };
                --counts[c];
            }
        }
        foreach (var kv in dic)
        {
            if (kv.Value.Count == 1)
            {
                var ans = new List<char>();
                for (var c = 0; c < kv.Key.List.Length; ++c) for (var i = 0; i < kv.Key.List[c]; ++i) ans.Add((char)(c + 'a'));
                return string.Concat(ans);
            }
        }
        return "-1";
    }
    class Data
    {
        public int Key;
        public int[] List;
        public Data(int[] list)
        {
            List = (int[]) list.Clone();
            var k = 0L;
            foreach (var li in list) k = (k * 11 + li) % 1_000_000_007;
            Key = (int)k;
        }
        public override bool Equals(object obj)
        {
            var b = obj as Data;
            if (Key != b.Key) return false;
            for (var i = 0; i < List.Length; ++i) if (List[i] != b.List[i]) return false;
            return true;
        }
        public override int GetHashCode()
        {
            return Key;
        }
    }
}
0