提出 #47043979


ソースコード 拡げる

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;

namespace Tasks;

using mint = E.ModuloInteger;

public class E
{
    public static void Main()
    {
        using var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }

    public static void Solve()
    {
        var N = Scanner.Scan<int>();
        var A = Scanner.ScanEnumerable<int>().ToArray();
        var iN = mint.Inverse(N);
        mint answer = 0;
        mint p = 1;
        for (var i = 0; i < N; i++)
        {
            answer += p * A[i] * iN;
            p += p * iN;
        }

        Console.WriteLine(answer);
    }

    public readonly struct ModuloInteger : IEquatable<ModuloInteger>,
        IAdditionOperators<ModuloInteger, ModuloInteger, ModuloInteger>,
        IDivisionOperators<ModuloInteger, ModuloInteger, ModuloInteger>,
        IMultiplyOperators<ModuloInteger, ModuloInteger, ModuloInteger>,
        ISubtractionOperators<ModuloInteger, ModuloInteger, ModuloInteger>,
        IEqualityOperators<ModuloInteger, ModuloInteger, bool>
    {
        public long Value { get; }
        // The modulo will be used as an editable property.
        // public static long Modulo { get; set; } = 998244353;
        // The constant modulo will be recommended to use for performances in use cases.
        public const long Modulo = 998244353;
        public ModuloInteger(int value)
        {
            Value = value % Modulo;
            if (Value < 0) Value += Modulo;
        }
        public ModuloInteger(long value)
        {
            Value = value % Modulo;
            if (Value < 0) Value += Modulo;
        }
        public static implicit operator int(ModuloInteger mint) => (int)mint.Value;
        public static implicit operator long(ModuloInteger mint) => mint.Value;
        public static implicit operator ModuloInteger(int value) => new(value);
        public static implicit operator ModuloInteger(long value) => new(value);
        public static ModuloInteger operator +(ModuloInteger left, ModuloInteger right) => left.Value + right.Value;
        public static ModuloInteger operator -(ModuloInteger left, ModuloInteger right) => left.Value - right.Value;
        public static ModuloInteger operator *(ModuloInteger left, ModuloInteger right) => left.Value * right.Value;
        public static ModuloInteger operator /(ModuloInteger left, ModuloInteger right) => left * right.Inverse();
        public static bool operator ==(ModuloInteger left, ModuloInteger right) => left.Equals(right);
        public static bool operator !=(ModuloInteger left, ModuloInteger right) => !left.Equals(right);
        public bool Equals(ModuloInteger other) => Value == other.Value;
        public override bool Equals(object obj) => obj is ModuloInteger other && Equals(other);
        public override int GetHashCode() => Value.GetHashCode();
        public override string ToString() => Value.ToString();
        public ModuloInteger Inverse() => Inverse(Value);
        public static ModuloInteger Inverse(long value)
        {
            if (value == 0) return 0;
            var (s, t, m0, m1) = (Modulo, value, 0L, 1L);
            while (t > 0)
            {
                var u = s / t;
                s -= t * u;
                m0 -= m1 * u;
                (s, t) = (t, s);
                (m0, m1) = (m1, m0);
            }
            if (m0 < 0) m0 += Modulo / s;
            return m0;
        }
        public ModuloInteger Power(long n) => Power(Value, n);
        public static ModuloInteger Power(long value, long n)
        {
            if (n < 0) throw new ArgumentException(nameof(n));
            var result = 1L;
            while (n > 0)
            {
                if ((n & 1) > 0) result = result * value % Modulo;
                value = value * value % Modulo;
                n >>= 1;
            }
            return result;
        }
    }

    public static class Scanner
    {
        public static T Scan<T>() where T : IConvertible => Convert<T>(ScanStringArray()[0]);
        public static (T1, T2) Scan<T1, T2>() where T1 : IConvertible where T2 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]));
        }
        public static (T1, T2, T3) Scan<T1, T2, T3>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]));
        }
        public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]));
        }
        public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]), Convert<T5>(input[4]));
        }
        public static (T1, T2, T3, T4, T5, T6) Scan<T1, T2, T3, T4, T5, T6>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible where T6 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]), Convert<T5>(input[4]), Convert<T6>(input[5]));
        }
        public static IEnumerable<T> ScanEnumerable<T>() where T : IConvertible => ScanStringArray().Select(Convert<T>);
        private static string[] ScanStringArray()
        {
            var line = Console.ReadLine()?.Trim() ?? string.Empty;
            return string.IsNullOrEmpty(line) ? Array.Empty<string>() : line.Split(' ');
        }
        private static T Convert<T>(string value) where T : IConvertible => (T)System.Convert.ChangeType(value, typeof(T));
    }
}

提出情報

提出日時
問題 E - Revenge of "The Salary of AtCoder Inc."
ユーザ AconCavy
言語 C# 11.0 (.NET 7.0.7)
得点 450
コード長 6481 Byte
結果 AC
実行時間 95 ms
メモリ 60748 KiB

コンパイルエラー

/judge/Main.cs(10,7): warning CS8981: The type name 'mint' only contains lower-cased ascii characters. Such names may become reserved for the language. [/judge/Main.csproj]

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 3
AC × 30
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt
ケース名 結果 実行時間 メモリ
sample_01.txt AC 60 ms 26216 KiB
sample_02.txt AC 57 ms 26240 KiB
sample_03.txt AC 51 ms 26132 KiB
test_01.txt AC 52 ms 26624 KiB
test_02.txt AC 47 ms 26088 KiB
test_03.txt AC 65 ms 35044 KiB
test_04.txt AC 46 ms 27024 KiB
test_05.txt AC 81 ms 54476 KiB
test_06.txt AC 50 ms 29912 KiB
test_07.txt AC 69 ms 46852 KiB
test_08.txt AC 50 ms 27088 KiB
test_09.txt AC 65 ms 40292 KiB
test_10.txt AC 53 ms 34372 KiB
test_11.txt AC 57 ms 34272 KiB
test_12.txt AC 78 ms 47816 KiB
test_13.txt AC 82 ms 56328 KiB
test_14.txt AC 58 ms 34688 KiB
test_15.txt AC 86 ms 53960 KiB
test_16.txt AC 60 ms 29800 KiB
test_17.txt AC 83 ms 59204 KiB
test_18.txt AC 86 ms 60468 KiB
test_19.txt AC 60 ms 38940 KiB
test_20.txt AC 57 ms 36268 KiB
test_21.txt AC 87 ms 57284 KiB
test_22.txt AC 92 ms 58216 KiB
test_23.txt AC 84 ms 60748 KiB
test_24.txt AC 95 ms 60408 KiB
test_25.txt AC 86 ms 60564 KiB
test_26.txt AC 90 ms 60436 KiB
test_27.txt AC 87 ms 60628 KiB