結果
問題 | No.978 Fibonacci Convolution Easy |
ユーザー | keymoon |
提出日時 | 2019-07-11 03:21:16 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 271 ms / 2,000 ms |
コード長 | 3,984 bytes |
コンパイル時間 | 955 ms |
コンパイル使用メモリ | 117,392 KB |
実行使用メモリ | 52,384 KB |
最終ジャッジ日時 | 2024-09-18 20:51:48 |
合計ジャッジ時間 | 4,344 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
23,024 KB |
testcase_01 | AC | 117 ms
36,356 KB |
testcase_02 | AC | 72 ms
30,380 KB |
testcase_03 | AC | 256 ms
52,384 KB |
testcase_04 | AC | 81 ms
29,916 KB |
testcase_05 | AC | 37 ms
25,884 KB |
testcase_06 | AC | 107 ms
36,876 KB |
testcase_07 | AC | 173 ms
41,600 KB |
testcase_08 | AC | 129 ms
37,844 KB |
testcase_09 | AC | 201 ms
46,500 KB |
testcase_10 | AC | 271 ms
49,536 KB |
testcase_11 | AC | 94 ms
27,136 KB |
testcase_12 | AC | 37 ms
19,712 KB |
testcase_13 | AC | 105 ms
28,544 KB |
testcase_14 | AC | 48 ms
21,376 KB |
testcase_15 | AC | 116 ms
30,080 KB |
testcase_16 | AC | 270 ms
49,536 KB |
testcase_17 | AC | 267 ms
49,536 KB |
testcase_18 | AC | 25 ms
19,072 KB |
testcase_19 | AC | 25 ms
18,944 KB |
testcase_20 | AC | 26 ms
18,944 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 np = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine(Solve(np[0], np[1])); } static ModInt Solve(int n, int p) { if (n == 1) return 0; ModInt res = 0; var fibs = new ModInt[n * 2]; fibs[0] = 0; fibs[1] = 1; for (int i = 2; i < fibs.Length; i++) fibs[i] = fibs[i - 1] * p + fibs[i - 2]; var lastFib = fibs[n - 1]; //端材を足す for (int i = 0; i < n; i++) { var mod = (i + n) % 4; if (mod == 1 || mod == 2) { res += lastFib * fibs[i]; } } for (int i = 1; i < n * 2; i++) { var mod = i % 4; if (mod == 1 || mod == 2) res += (Min(i, (n - 1) * 2 - i) + 1) / 2 * fibs[i]; } return res; } static ModInt Stupid(int n, int p) { if (n == 1) return 0; var fibs = new ModInt[n]; fibs[0] = 0; fibs[1] = 1; for (int i = 2; i < n; i++) fibs[i] = fibs[i - 1] * p + fibs[i - 2]; ModInt res = 0; for (int i = 0; i < n; i++) for (int j = i; j < n; j++) res += fibs[i] * fibs[j]; return res; } } 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) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? 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, int b) => new ModInt() { Data = a.Data * b % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, long b) => a * new ModInt(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt a, ModInt b) => new ModInt() { Data = a.Data * GetInverse(b) % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => Data.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GetInverse(long a) { long div, p = MOD, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + MOD; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + MOD; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } }