結果
問題 | No.980 Fibonacci Convolution Hard |
ユーザー | keymoon |
提出日時 | 2019-07-11 21:34:41 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 361 ms / 2,000 ms |
コード長 | 2,874 bytes |
コンパイル時間 | 3,686 ms |
コンパイル使用メモリ | 114,156 KB |
実行使用メモリ | 58,432 KB |
最終ジャッジ日時 | 2024-09-17 11:46:37 |
合計ジャッジ時間 | 11,742 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 358 ms
56,388 KB |
testcase_01 | AC | 354 ms
56,272 KB |
testcase_02 | AC | 354 ms
56,004 KB |
testcase_03 | AC | 357 ms
58,432 KB |
testcase_04 | AC | 359 ms
56,268 KB |
testcase_05 | AC | 360 ms
48,128 KB |
testcase_06 | AC | 359 ms
48,128 KB |
testcase_07 | AC | 361 ms
48,256 KB |
testcase_08 | AC | 356 ms
48,128 KB |
testcase_09 | AC | 356 ms
48,256 KB |
testcase_10 | AC | 359 ms
48,000 KB |
testcase_11 | AC | 360 ms
47,872 KB |
testcase_12 | AC | 360 ms
47,872 KB |
testcase_13 | AC | 360 ms
48,256 KB |
testcase_14 | AC | 356 ms
56,512 KB |
testcase_15 | AC | 355 ms
54,348 KB |
testcase_16 | AC | 339 ms
48,256 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.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using static System.Math; using Debug = System.Diagnostics.Debug; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { var p = int.Parse(Console.ReadLine()); Debug.Assert(1 <= p && p <= 1000000000); var fibs = GetFibs(p, 2000000); var res = Solve(fibs); //var res = SolveStupid(fibs); var Q = int.Parse(Console.ReadLine()); Debug.Assert(2 <= Q && Q <= 200000); StringBuilder builder = new StringBuilder(); for (int i = 0; i < Q; i++) { var q = int.Parse(Console.ReadLine()); Debug.Assert(1 <= q && q <= 2000000); builder.AppendLine(res[q].ToString()); } Console.Write(builder.ToString()); } static ModInt[] Solve(ModInt[] fibs) { ModInt[] res = new ModInt[fibs.Length]; res[2] = 0; res[3] = 0; for (int i = 4; i < res.Length; i++) { res[i] = (i - 3) * fibs[i - 2] - res[i - 2]; } return res; } static ModInt[] SolveStupid(ModInt[] fibs) { ModInt[] res = new ModInt[fibs.Length * 2]; for (int i = 1; i < fibs.Length; i++) for (int j = 1; j < fibs.Length; j++) res[i + j] += fibs[i] * fibs[j]; return res; } static ModInt[] GetFibs(int p, int count) { ModInt[] fibs = new ModInt[count + 1]; fibs[1] = 0; fibs[2] = 1; for (int i = 3; i < fibs.Length; i++) fibs[i] = fibs[i - 1] * p + fibs[i - 2]; return fibs; } } struct ModInt { const int MOD = 1000000007; long Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt modInt) => modInt.Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long val) => new ModInt(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) { long res = a.Data + b.Data; return new ModInt() { Data = res >= MOD ? res - MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, long b) => a.Data + b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % MOD }; public override string ToString() => Data.ToString(); }