結果

問題 No.3491 右結合的総乗
コンテスト
ユーザー kakel-san
提出日時 2026-04-03 22:39:22
言語 C#(csc)
(csc 3.9.0)
コンパイル:
csc -langversion:latest -unsafe -warn:0 -o+ /r:System.Numerics.dll _filename_ -out:a.exe
実行:
/usr/bin/mono a.exe
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,245 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,745 ms
コンパイル使用メモリ 114,500 KB
実行使用メモリ 28,960 KB
最終ジャッジ日時 2026-04-03 22:39:41
合計ジャッジ時間 7,355 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #
raw source code

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

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();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m) = (c[0], c[1]);
        var a = NList;
        var s = NList;
        var set = new HashSet<int>(s);
        var add = new HashSet<int>();
        for (var i = 0; i < s.Length; ++i) for (var j = i; j < s.Length; ++j) if (!set.Contains(a[s[i] + s[j]]))
        {
            set.Add(a[s[i] + s[j]]);
            add.Add(a[s[i] + s[j]]);
        }
        while (add.Count > 0)
        {
            var nadd = new HashSet<int>();
            foreach (var ai in add) for (var i = 0; i < s.Length; ++i) if (!set.Contains(a[ai + s[i]]))
            {
                set.Add(a[ai + s[i]]);
                nadd.Add(a[ai + s[i]]);
            }
            add = nadd;
        }
        WriteLine(set.Count);
    }
}
0