結果
問題 | No.980 Fibonacci Convolution Hard |
ユーザー | keymoon |
提出日時 | 2019-07-11 21:14:03 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,210 ms / 2,000 ms |
コード長 | 2,708 bytes |
コンパイル時間 | 2,145 ms |
コンパイル使用メモリ | 114,512 KB |
実行使用メモリ | 52,352 KB |
最終ジャッジ日時 | 2024-09-17 11:21:01 |
合計ジャッジ時間 | 25,490 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,171 ms
52,224 KB |
testcase_01 | AC | 1,167 ms
52,224 KB |
testcase_02 | AC | 1,160 ms
52,224 KB |
testcase_03 | AC | 1,179 ms
52,224 KB |
testcase_04 | AC | 1,175 ms
52,352 KB |
testcase_05 | AC | 1,160 ms
52,224 KB |
testcase_06 | AC | 1,153 ms
52,352 KB |
testcase_07 | AC | 1,175 ms
52,096 KB |
testcase_08 | AC | 1,158 ms
51,968 KB |
testcase_09 | AC | 1,164 ms
52,224 KB |
testcase_10 | AC | 1,210 ms
52,096 KB |
testcase_11 | AC | 1,160 ms
52,096 KB |
testcase_12 | AC | 1,168 ms
52,096 KB |
testcase_13 | AC | 1,160 ms
51,968 KB |
testcase_14 | AC | 1,176 ms
52,224 KB |
testcase_15 | AC | 1,164 ms
52,096 KB |
testcase_16 | AC | 1,112 ms
52,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.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(1 <= Q && Q <= 200000); for (int i = 0; i < Q; i++) { var q = int.Parse(Console.ReadLine()); Debug.Assert(1 <= q && q <= 2000000); Console.WriteLine(res[q]); } } 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 }; }