結果

問題 No.2235 Line Up Colored Balls
ユーザー 👑 kakel-sankakel-san
提出日時 2023-07-26 21:26:26
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 3,273 bytes
コンパイル時間 5,545 ms
コンパイル使用メモリ 115,552 KB
実行使用メモリ 35,120 KB
最終ジャッジ日時 2024-04-14 10:58:13
合計ジャッジ時間 6,796 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
25,260 KB
testcase_01 AC 29 ms
25,212 KB
testcase_02 AC 29 ms
25,336 KB
testcase_03 AC 28 ms
25,080 KB
testcase_04 AC 69 ms
31,316 KB
testcase_05 AC 28 ms
25,208 KB
testcase_06 AC 29 ms
25,464 KB
testcase_07 AC 60 ms
31,800 KB
testcase_08 AC 28 ms
27,140 KB
testcase_09 AC 28 ms
27,016 KB
testcase_10 AC 29 ms
25,220 KB
testcase_11 AC 28 ms
25,216 KB
testcase_12 AC 29 ms
27,248 KB
testcase_13 AC 28 ms
27,140 KB
testcase_14 AC 29 ms
25,132 KB
testcase_15 AC 28 ms
25,208 KB
testcase_16 AC 29 ms
27,400 KB
testcase_17 AC 29 ms
27,120 KB
testcase_18 AC 69 ms
31,036 KB
testcase_19 AC 70 ms
35,120 KB
testcase_20 AC 70 ms
31,300 KB
testcase_21 AC 69 ms
33,092 KB
testcase_22 AC 69 ms
31,152 KB
testcase_23 AC 70 ms
30,900 KB
testcase_24 AC 69 ms
30,912 KB
testcase_25 AC 68 ms
30,780 KB
testcase_26 AC 69 ms
30,900 KB
testcase_27 AC 69 ms
33,196 KB
testcase_28 AC 63 ms
31,956 KB
testcase_29 AC 62 ms
29,888 KB
testcase_30 AC 62 ms
31,940 KB
testcase_31 AC 63 ms
31,824 KB
testcase_32 AC 60 ms
31,812 KB
testcase_33 AC 59 ms
27,556 KB
testcase_34 AC 62 ms
29,948 KB
testcase_35 AC 63 ms
29,632 KB
testcase_36 AC 61 ms
29,828 KB
testcase_37 AC 62 ms
28,108 KB
testcase_38 AC 38 ms
28,112 KB
testcase_39 AC 33 ms
27,724 KB
testcase_40 AC 37 ms
26,416 KB
testcase_41 AC 54 ms
27,748 KB
testcase_42 AC 58 ms
30,104 KB
testcase_43 AC 34 ms
26,160 KB
testcase_44 AC 46 ms
29,332 KB
testcase_45 AC 34 ms
25,848 KB
testcase_46 AC 63 ms
28,324 KB
testcase_47 AC 45 ms
27,380 KB
testcase_48 AC 68 ms
30,908 KB
testcase_49 AC 68 ms
29,112 KB
testcase_50 AC 68 ms
33,084 KB
testcase_51 AC 68 ms
33,072 KB
testcase_52 AC 68 ms
28,984 KB
testcase_53 AC 68 ms
31,040 KB
testcase_54 AC 68 ms
30,904 KB
testcase_55 AC 68 ms
31,028 KB
testcase_56 AC 69 ms
32,948 KB
testcase_57 AC 69 ms
31,152 KB
testcase_58 AC 28 ms
23,352 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 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();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var a = NList;
        var sum = a.Sum();
        var mod = 1_000_000_007;
        var revsum = Exp(sum, mod - 2, mod);
        var ans = (long)sum;
        foreach (var ai in a)
        {
            ans = (ans + mod - (long)ai * (ai - 1) % mod * revsum % mod) % mod;
        }
        WriteLine(ans);
    }
    static long Exp(int n, int k, int mod)
    {
        if (k == 0) return 1;
        if (k == 1) return n % mod;
        var half = Exp(n, k / 2, mod);
        var result = (half * half) % mod;
        return ((k % 2) == 0) ? result : ((result * n) % mod);
    }
    static List<int[]> NCRList(int n, int r)
    {
        var res = new List<int[]>();
        _NCRList(n, r, new List<int>(), res);
        return res;
    }
    static void _NCRList(int n, int r, List<int> list, List<int[]> res)
    {
        if (list.Count == r) res.Add(list.ToArray());
        for (var i = list.Count == 0 ? 0 : (list.Last() + 1); i < n; ++i)
        {
            list.Add(i);
            _NCRList(n, r, list, res);
            list.RemoveAt(list.Count - 1);
        }
    }
    class NCR
    {
        int[] facts;
        int[] revFacts;
        int mod;
        public NCR(int n, int mod)
        {
            facts = new int[n + 1];
            revFacts = new int[n + 1];
            this.mod = mod;
            facts[0] = 1;
            var tmp = 1L;
            for (var i = 1; i <= n; ++i)
            {
                tmp = (tmp * i) % mod;
                facts[i] = (int)tmp;
            }
            tmp = Exp(facts[n], mod - 2);
            revFacts[n] = (int)tmp;
            for (var i = n; i > 1; --i)
            {
                tmp = (tmp * i) % mod;
                revFacts[i - 1] = (int)tmp;
            }
            revFacts[0] = 1;
        }
        public long Exp(long n, long k)
        {
            n = n % mod;
            if (k == 0) return 1;
            if (k == 1) return n;
            var half = Exp(n, k / 2);
            var result = (half * half) % mod;
            return ((k % 2) == 0) ? result : ((result * n) % mod);
        }
        public long Calc(int n, int r)
        {
            return (long)facts[n] * revFacts[r] % mod * revFacts[n - r] % mod;
        }
        /// <summary>nが大きくrが小さい場合の計算</summary>
        public long Calc2(int n, int r)
        {
            var tmp = 1L;
            for (var i = 0; i < r; ++i)
            {
                tmp = tmp * (n - i) % mod;
            }
            return tmp * revFacts[r] % mod;
        }
        public long NPR(int n, int r)
        {
            return (long)facts[n] * revFacts[r] % mod;
        }
        public long Fact(int n)
        {
            return facts[n];
        }
        public long RevFact(int n)
        {
            return revFacts[n];
        }
    }
}
0