結果

問題 No.1073 無限すごろく
ユーザー Yusei KatoYusei Kato
提出日時 2020-06-22 23:21:21
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 2,933 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 66,288 KB
実行使用メモリ 28,984 KB
最終ジャッジ日時 2023-09-16 19:33:54
合計ジャッジ時間 4,560 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
22,752 KB
testcase_01 AC 54 ms
22,860 KB
testcase_02 AC 57 ms
22,664 KB
testcase_03 AC 53 ms
22,856 KB
testcase_04 AC 52 ms
20,708 KB
testcase_05 AC 52 ms
22,728 KB
testcase_06 AC 52 ms
20,772 KB
testcase_07 AC 52 ms
20,772 KB
testcase_08 AC 52 ms
20,740 KB
testcase_09 AC 55 ms
20,764 KB
testcase_10 AC 53 ms
22,756 KB
testcase_11 AC 54 ms
20,596 KB
testcase_12 AC 53 ms
20,816 KB
testcase_13 AC 71 ms
21,636 KB
testcase_14 AC 74 ms
21,748 KB
testcase_15 AC 80 ms
24,248 KB
testcase_16 AC 95 ms
23,876 KB
testcase_17 AC 94 ms
25,968 KB
testcase_18 AC 94 ms
27,980 KB
testcase_19 AC 106 ms
24,984 KB
testcase_20 AC 114 ms
25,560 KB
testcase_21 AC 128 ms
28,984 KB
testcase_22 AC 131 ms
25,044 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Linq;

namespace Problem1073
{
    class Program
    {
        static void Main(string[] args)
        {
            const long mod = 7 + (long)1e9;
            long N = GetLong();
            var table = new long[N + 1];
            for(int i = 0; i <= N; i++)
            {
                switch(i)
                {
                    case 0:
                        table[i] = 1;
                        break;
                    case 1:
                        table[i] = ModInv(6, mod);
                        break;
                    case 2:
                        table[i] = (table[0] + table[1]) % mod * table[1] % mod;
                        break;
                    case 3:
                        table[i] = ((table[0] + table[1]) %mod + table[2]) % mod * table[1] % mod;
                        break;
                    case 4:
                        table[i] = (((table[0] + table[1]) % mod + table[2]) % mod + table[3]) % mod * table[1] % mod;
                        break;
                    case 5:
                        table[i] = ((((table[0] + table[1]) % mod + table[2]) % mod + table[3]) % mod + table[4]) % mod * table[1] % mod;
                        break;
                    case 6:
                        table[i] = (((((table[0] + table[1]) % mod + table[2]) % mod + table[3]) % mod + table[4]) % mod + table[5]) % mod * table[1] % mod;
                        break;
                    default:
                        table[i] = (((((table[i - 6] + table[i - 5]) % mod + table[i - 4]) % mod + table[i - 3]) % mod + table[i - 2]) % mod + table[i - 1]) % mod * table[1] % mod;
                        break;

                }
            }
            Console.WriteLine(table[N]);
        }

        public static long ModInv(long n, long mod)
        {
            long b = mod;
            long u = 1;
            long v = 0;
            while (b != 0)
            {
                long t = n / b;
                n -= t * b;
                Swap(ref n, ref b);
                u -= t * v;
                Swap(ref u, ref v);
            }
            u %= mod;
            if(u < 0)
            {
                u += mod;
            }
            return u;
        }

        static void Swap(ref long a, ref long b)
        {
            long temp = a;
            a = b;
            b = temp;
        }

        public static int GetInt() => int.Parse(Console.ReadLine());
        public static int[] GetIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static double[] GetDoubleArray() => Console.ReadLine().Split().Select(double.Parse).ToArray();
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static long[] GetLongArray() => Console.ReadLine().Split().Select(long.Parse).ToArray();


    }
}
0