結果

問題 No.1325 Subsequence Score
ユーザー eSeFeSeF
提出日時 2020-12-22 15:42:09
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 317 ms / 2,000 ms
コード長 5,794 bytes
コンパイル時間 1,137 ms
コンパイル使用メモリ 118,860 KB
実行使用メモリ 62,472 KB
最終ジャッジ日時 2024-09-21 14:14:37
合計ジャッジ時間 6,964 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
18,944 KB
testcase_01 AC 24 ms
18,944 KB
testcase_02 AC 24 ms
18,816 KB
testcase_03 AC 29 ms
19,456 KB
testcase_04 AC 29 ms
19,584 KB
testcase_05 AC 30 ms
19,328 KB
testcase_06 AC 29 ms
19,456 KB
testcase_07 AC 29 ms
19,712 KB
testcase_08 AC 24 ms
19,072 KB
testcase_09 AC 27 ms
19,584 KB
testcase_10 AC 28 ms
19,328 KB
testcase_11 AC 27 ms
19,456 KB
testcase_12 AC 28 ms
19,456 KB
testcase_13 AC 308 ms
61,880 KB
testcase_14 AC 108 ms
36,224 KB
testcase_15 AC 272 ms
58,180 KB
testcase_16 AC 296 ms
59,748 KB
testcase_17 AC 138 ms
40,448 KB
testcase_18 AC 105 ms
34,688 KB
testcase_19 AC 313 ms
62,400 KB
testcase_20 AC 62 ms
25,344 KB
testcase_21 AC 119 ms
38,016 KB
testcase_22 AC 144 ms
43,136 KB
testcase_23 AC 313 ms
62,212 KB
testcase_24 AC 317 ms
62,464 KB
testcase_25 AC 310 ms
62,352 KB
testcase_26 AC 301 ms
62,472 KB
testcase_27 AC 302 ms
62,216 KB
testcase_28 AC 24 ms
18,816 KB
testcase_29 AC 24 ms
18,944 KB
testcase_30 AC 24 ms
18,816 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
//using ModInt = AtCoder_MOD.ModInt<AtCoder_MOD.Mod1000000007>;using static AtCoder_MOD.ModCalc<AtCoder_MOD.Mod1000000007>;
using ModInt = AtCoder_MOD.ModInt<AtCoder_MOD.Mod998244353>;using static AtCoder_MOD.ModCalc<AtCoder_MOD.Mod998244353>;
namespace AtCoder_Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            if (N == 1) { Console.WriteLine(new ModInt(A[0]));return; }
            ModInt ans = 0;
            ModInt pw = 1;
            for (var i = 0; i < N - 2; i++) pw *= 2;
            for(var i = 0; i < N; i++)
            {
                ModInt K = i + 1;
                ans += A[i] * (K + 1) * pw;
            }
            Console.WriteLine(ans);
        }
    }
}
namespace AtCoder_MOD
{
    public interface IMod
    {
        int Mod { get; }
        // isprime ?
    }
    public interface INTTFriendly
    {
        int primitive_root { get; }
    }
    public readonly struct Mod1000000007 : IMod
    {
        public int Mod => 1000000007;
    }
    public readonly struct Mod998244353 : IMod, INTTFriendly
    {
        public int Mod => 998244353;
        public int primitive_root => 3;
    }
    public struct ModInt<T> where T : IMod
    {
        private int value;
        // 0 <= x < mod 以外でも OK
        public ModInt(int x)
        {
            if (x < 0) x = (x % default(T).Mod) + default(T).Mod;
            else if (x >= default(T).Mod) x %= default(T).Mod;
            value = x;
        }
        public ModInt(long x)
        {
            if (x < 0) x = (x % default(T).Mod) + default(T).Mod;
            else if (x >= default(T).Mod) x %= default(T).Mod;
            value = (int)x;
        }
        // 0 <= x < mod
        public ModInt(uint x) => value = (int)x;
        
        public static ModInt<T> operator +(ModInt<T> a, ModInt<T> b)
        {
            var nv = a.value + b.value;
            if (nv >= default(T).Mod) nv -= default(T).Mod;
            return new ModInt<T>((uint)nv);
        }

        public static ModInt<T> operator -(ModInt<T> a, ModInt<T> b)
        {
            var nv = a.value - b.value;
            if (nv < 0) nv += default(T).Mod;
            return new ModInt<T>((uint)nv);
        }


        public static ModInt<T> operator *(ModInt<T> a, ModInt<T> b) => new ModInt<T>((uint)(((long)a.value * b.value) % default(T).Mod));
        //符号
        public static ModInt<T> operator +(ModInt<T> a) => a;
        public static ModInt<T> operator -(ModInt<T> a) => a.value == 0 ? a : new ModInt<T>((uint)(default(T).Mod - a.value));
        public ModInt<T> Pow(long n)
        {
            if (n < 0) return Pow(-n).Pow(default(T).Mod - 2);
            var p = this;
            var ret = new ModInt<T>(1u);
            while (n > 0)
            {
                if ((n & 1) != 0) ret *= p;
                p *= p;
                n >>= 1;
            }
            return ret;
        }
        //Todo Inv を ExtGcd での実装にしたい
        public ModInt<T> Inverse() => this.Pow(default(T).Mod - 2);
        public static ModInt<T> operator /(ModInt<T> a, ModInt<T> b) => (a * b.Inverse());
        public static bool operator ==(ModInt<T> a, ModInt<T> b) => a.value == b.value;
        public static bool operator !=(ModInt<T> a, ModInt<T> b) => a.value != b.value;
        public override bool Equals(object obj) => obj is ModInt<T> && this == (ModInt<T>)obj;
        public override int GetHashCode() => value.GetHashCode();
        public override string ToString() => value.ToString();


        //キャスト
        public static implicit operator ModInt<T>(int n) => new ModInt<T>(n);
        public static implicit operator ModInt<T>(long n) => new ModInt<T>(n);
        public static explicit operator int(ModInt<T> a) => a.value;
        public static explicit operator long(ModInt<T> a) => a.value;
    }
    public static class ModCalc<T> where T : IMod
    {
        static List<ModInt<T>> fac = new List<ModInt<T>>() { 1 };
        static List<ModInt<T>> facinv;
        static int MAX_N;
        // Do Use Init(Max_n) Before using other functions
        public static void Init(int n)
        {
            MAX_N = n;
            for (int i = 1; i <= n; i++) fac.Add(fac.Last() * i);
            facinv = new List<ModInt<T>>() { fac[n].Inverse() };
            for (int i = n; i > 0; i--) facinv.Add(facinv.Last() * i);
            facinv.Reverse();
        }
        public static void Reset()
        {
            MAX_N = -1;
            fac.Clear();
            facinv.Clear();
        }
        public static ModInt<T> Fac(int n)
        {
            Debug.Assert(n <= MAX_N);
            return fac[n];
        }
        public static ModInt<T> Finv(int n)
        {
            Debug.Assert(n <= MAX_N);
            return facinv[n];
        }
        public static ModInt<T> Comb(int n, int r)
        {
            Debug.Assert(n <= MAX_N);
            if (n < 0 || r < 0 || n < r) return 0;
            return fac[n] * facinv[n - r] * facinv[r];
        }
        public static ModInt<T> ModPow(long x, long n) => new ModInt<T>(x).Pow(n);
        public static ModInt<T> ModPow(int x, long n) => new ModInt<T>((uint)x).Pow(n);
        public static ModInt<T> ModPow(ModInt<T> x, long n) => x.Pow(n);
        public static ModInt<T> Inv(long x) => new ModInt<T>(x).Inverse();
        public static ModInt<T> Inv(int x) => new ModInt<T>((uint)x).Inverse();

        public static List<ModInt<T>> GetFac() => fac;
        public static List<ModInt<T>> GetFacInv() => facinv;
    }
}
0