結果
問題 | No.797 Noelちゃんとピラミッド |
ユーザー | sekiya9311 |
提出日時 | 2019-10-28 00:45:25 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 229 ms / 2,000 ms |
コード長 | 7,475 bytes |
コンパイル時間 | 2,471 ms |
コンパイル使用メモリ | 112,512 KB |
実行使用メモリ | 37,376 KB |
最終ジャッジ日時 | 2024-09-14 21:09:54 |
合計ジャッジ時間 | 17,777 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 157 ms
19,968 KB |
testcase_01 | AC | 160 ms
20,096 KB |
testcase_02 | AC | 157 ms
19,968 KB |
testcase_03 | AC | 227 ms
37,376 KB |
testcase_04 | AC | 228 ms
37,248 KB |
testcase_05 | AC | 227 ms
37,248 KB |
testcase_06 | AC | 226 ms
37,376 KB |
testcase_07 | AC | 226 ms
37,248 KB |
testcase_08 | AC | 228 ms
37,120 KB |
testcase_09 | AC | 226 ms
37,248 KB |
testcase_10 | AC | 227 ms
37,120 KB |
testcase_11 | AC | 226 ms
37,376 KB |
testcase_12 | AC | 227 ms
37,376 KB |
testcase_13 | AC | 228 ms
37,248 KB |
testcase_14 | AC | 227 ms
37,248 KB |
testcase_15 | AC | 225 ms
37,376 KB |
testcase_16 | AC | 228 ms
37,248 KB |
testcase_17 | AC | 227 ms
37,376 KB |
testcase_18 | AC | 229 ms
37,248 KB |
testcase_19 | AC | 227 ms
37,248 KB |
testcase_20 | AC | 226 ms
37,376 KB |
testcase_21 | AC | 229 ms
37,376 KB |
testcase_22 | AC | 227 ms
37,248 KB |
testcase_23 | AC | 209 ms
34,176 KB |
testcase_24 | AC | 175 ms
24,192 KB |
testcase_25 | AC | 202 ms
31,872 KB |
testcase_26 | AC | 201 ms
31,744 KB |
testcase_27 | AC | 226 ms
36,736 KB |
testcase_28 | AC | 222 ms
35,968 KB |
testcase_29 | AC | 171 ms
23,296 KB |
testcase_30 | AC | 173 ms
23,936 KB |
testcase_31 | AC | 210 ms
34,176 KB |
testcase_32 | AC | 181 ms
25,344 KB |
testcase_33 | AC | 200 ms
31,872 KB |
testcase_34 | AC | 189 ms
27,392 KB |
testcase_35 | AC | 227 ms
37,248 KB |
testcase_36 | AC | 168 ms
22,272 KB |
testcase_37 | AC | 218 ms
35,840 KB |
testcase_38 | AC | 223 ms
36,224 KB |
testcase_39 | AC | 202 ms
32,000 KB |
testcase_40 | AC | 168 ms
22,272 KB |
testcase_41 | AC | 171 ms
22,912 KB |
testcase_42 | AC | 200 ms
31,488 KB |
testcase_43 | AC | 157 ms
19,968 KB |
testcase_44 | AC | 158 ms
20,224 KB |
testcase_45 | AC | 158 ms
20,096 KB |
testcase_46 | AC | 158 ms
19,968 KB |
testcase_47 | AC | 157 ms
19,968 KB |
testcase_48 | AC | 157 ms
19,968 KB |
testcase_49 | AC | 159 ms
19,968 KB |
testcase_50 | AC | 158 ms
19,968 KB |
testcase_51 | AC | 157 ms
20,224 KB |
testcase_52 | AC | 158 ms
20,096 KB |
testcase_53 | AC | 158 ms
19,968 KB |
testcase_54 | AC | 158 ms
20,096 KB |
testcase_55 | AC | 158 ms
20,224 KB |
testcase_56 | AC | 158 ms
20,096 KB |
testcase_57 | AC | 157 ms
19,840 KB |
testcase_58 | AC | 159 ms
20,096 KB |
testcase_59 | AC | 159 ms
20,096 KB |
testcase_60 | AC | 158 ms
19,968 KB |
testcase_61 | AC | 160 ms
20,096 KB |
testcase_62 | AC | 158 ms
20,096 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; namespace ProgrammingContestTemplateByDotNetCore { #region "Input and Output Classes" class Scanner : IDisposable { private readonly Queue<string> _buffer; private readonly char[] _sep; private readonly TextReader _reader; public Scanner(TextReader reader = null, char[] sep = null) { _buffer = new Queue<string>(); _sep = sep ?? new[] { ' ' }; _reader = reader ?? Console.In; } public Scanner(string path, char[] sep = null) : this(new StreamReader(path), sep) { } private void CheckBuffer() { if (_buffer.Any() || _reader.Peek() == -1) return; string str = string.Empty; for (; string.IsNullOrWhiteSpace(str); str = _reader.ReadLine()) { } var values = str.Split(_sep).Where(s => !string.IsNullOrWhiteSpace(s)); foreach (var item in values) { _buffer.Enqueue(item); } } public string Next() { CheckBuffer(); return _buffer.Dequeue(); } public string[] GetStringArray(int count) => Enumerable.Range(0, count) .Select(e => Next()) .ToArray(); public int NextInt() => int.Parse(Next()); public int[] GetIntArray(int count) => Enumerable.Range(0, count) .Select(e => NextInt()) .ToArray(); public long NextLong() => long.Parse(Next()); public long[] GetLongArray(int count) => Enumerable.Range(0, count) .Select(e => NextLong()) .ToArray(); public double NextDouble() => double.Parse(Next()); public double[] GetDoubleArray(int count) => Enumerable.Range(0, count) .Select(e => NextDouble()) .ToArray(); public decimal NextDecimal() => decimal.Parse(Next()); public decimal[] GetDecimalArray(int count) => Enumerable.Range(0, count) .Select(e => NextDecimal()) .ToArray(); public BigInteger NextBigInt() => BigInteger.Parse(Next()); public BigInteger[] GetBigIntArray(int count) => Enumerable.Range(0, count) .Select(e => NextBigInt()) .ToArray(); public bool IsEnd { get { CheckBuffer(); return !_buffer.Any(); } } public void Dispose() { if (!_reader.Equals(Console.In)) _reader.Dispose(); } } class Writer : IDisposable { private readonly TextWriter _writer; private readonly StringBuilder _cache; private readonly bool _isReactive; public Writer(TextWriter writer = null, bool isReactive = false) { _writer = writer ?? Console.Out; _isReactive = isReactive; if (!_isReactive) _cache = new StringBuilder(); } public Writer(string path) : this(new StreamWriter(path)) { } public Writer(bool isReactive) : this(null, isReactive) { } public void Write(object value) { if (_isReactive) { _writer.Write(value); _writer.Flush(); } else { _cache.Append(value); } } public void WriteFormat(string format, params object[] values) { var value = string.Format(format, values); Write(value); } public void WriteLine(object value = null) { Write($"{value}{Environment.NewLine}"); } public void WriteLine(string format, params object[] values) { WriteFormat($"{format}{Environment.NewLine}", values); } public void Dispose() { if (!_isReactive) { _writer.Write(_cache); _writer.Flush(); } if (!_writer.Equals(Console.Out)) { _writer.Dispose(); } } } public static class Extensions { public static void Set<TKey, TValue>( this IDictionary<TKey, TValue> source, TKey key, TValue value) { if (source.ContainsKey(key)) source[key] = value; else source.Add(key, value); } public static void Update<TKey, TValue>( this IDictionary<TKey, TValue> source, TKey key, Func<TValue, TValue> update) { if (!source.ContainsKey(key)) source.Add(key, default); source[key] = update(source[key]); } } #endregion class MainClass : IDisposable { #region "Template" /// <summary> 入力を受け取る </summary> private readonly Scanner sc; /// <summary> 出力を行う </summary> private readonly Writer wr; private const string _inputFile = "input.txt"; private const string _outFile = "output.txt"; static void Main(string[] args) { using (new MainClass()) { } } public MainClass() { wr = new Writer(_isReactive); // TODO: ファイルに出力したい場合はこっち → wr = new Writer(_outFile); #if DEBUG // 手元では、ファイルから入力を受け取る sc = new Scanner(_inputFile); #else // 提出時、標準入力から受け取る sc = new Scanner(); #endif Solve(); } public void Dispose() { sc?.Dispose(); wr?.Dispose(); } #endregion void Solve() { Calc(); int N = sc.NextInt(); var a = sc.GetLongArray(N); long ans = 0; for (int i = 0; i < N; i++) { ans += a[i] * nCr(N - 1, i, Mod) % Mod; ans %= Mod; } wr.WriteLine(ans); } const int Mod = (int)1e9 + 7; const int Max = (int)1e5 + 10; long[] fact = new long[Max]; long[] invFact = new long[Max]; void Calc() { fact[0] = invFact[0] = 1; for (int i = 1; i < Max; i++) { fact[i] = fact[i - 1] * i % Mod; invFact[i] = Inv(fact[i], Mod); } } long nCr(long n, long r, long mod) { return fact[n] * invFact[n - r] % mod * invFact[r] % mod; } long Pow2(long a, long mod) => a * a % mod; long PowMod(long a, long p, long mod) => p == 0 ? 1 : p % 2 == 1 ? a * PowMod(a, p - 1, mod) % mod : Pow2(PowMod(a, p / 2, mod), mod); long Inv(long a, long mod) => PowMod(a, mod - 2, mod); /// <summary> /// TODO: リアクティブ問題か否かを指定してね♪ /// </summary> private const bool _isReactive = false; } }