結果

問題 No.1704 Many Bus Stops (easy)
ユーザー 👑 kakel-sankakel-san
提出日時 2023-12-30 21:23:54
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 781 ms / 2,000 ms
コード長 2,263 bytes
コンパイル時間 7,879 ms
コンパイル使用メモリ 158,692 KB
実行使用メモリ 202,448 KB
最終ジャッジ日時 2023-12-30 21:24:28
合計ジャッジ時間 33,023 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
31,268 KB
testcase_01 AC 752 ms
54,820 KB
testcase_02 AC 298 ms
55,076 KB
testcase_03 AC 298 ms
55,076 KB
testcase_04 AC 298 ms
55,204 KB
testcase_05 AC 308 ms
55,076 KB
testcase_06 AC 298 ms
55,204 KB
testcase_07 AC 302 ms
55,076 KB
testcase_08 AC 298 ms
55,076 KB
testcase_09 AC 309 ms
55,076 KB
testcase_10 AC 300 ms
55,076 KB
testcase_11 AC 301 ms
55,076 KB
testcase_12 AC 299 ms
55,076 KB
testcase_13 AC 307 ms
55,204 KB
testcase_14 AC 297 ms
55,076 KB
testcase_15 AC 305 ms
55,076 KB
testcase_16 AC 302 ms
55,204 KB
testcase_17 AC 313 ms
55,076 KB
testcase_18 AC 300 ms
55,204 KB
testcase_19 AC 303 ms
55,076 KB
testcase_20 AC 306 ms
55,076 KB
testcase_21 AC 298 ms
55,076 KB
testcase_22 AC 746 ms
54,820 KB
testcase_23 AC 772 ms
54,820 KB
testcase_24 AC 764 ms
54,820 KB
testcase_25 AC 755 ms
54,820 KB
testcase_26 AC 774 ms
54,820 KB
testcase_27 AC 769 ms
54,820 KB
testcase_28 AC 754 ms
54,820 KB
testcase_29 AC 779 ms
54,820 KB
testcase_30 AC 749 ms
54,820 KB
testcase_31 AC 781 ms
54,820 KB
testcase_32 AC 774 ms
54,820 KB
testcase_33 AC 748 ms
54,820 KB
testcase_34 AC 773 ms
54,820 KB
testcase_35 AC 778 ms
54,820 KB
testcase_36 AC 756 ms
54,820 KB
testcase_37 AC 775 ms
54,820 KB
testcase_38 AC 778 ms
54,820 KB
testcase_39 AC 759 ms
54,820 KB
testcase_40 AC 774 ms
54,820 KB
testcase_41 AC 748 ms
202,448 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (109 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var t = NN;
        var ans = new long[t];
        for (var i = 0; i < t; ++i)
        {
            var n = NN;
            ans[i] = Bus(n);
        }
        WriteLine(string.Join("\n", ans));
    }
    static long Bus(int n)
    {
        var a = new long[][] { new long[] { 0, 1, 0, 0, 0, 0 } };
        var b = Matrix.Mul(a, Matrix.Pow(x, n));
        return b[0][1];
    }
    static int r3 = 333333336;
    static long[][] x = new long[][]
    {
        new long[] { 0, 1, 0, 0, 0, 0 },
        new long[] { 0, r3, r3, 0, r3, 0 },
        new long[] { 0, 0, 0, 1, 0, 0 },
        new long[] { r3, 0, 0, r3, r3, 0 },
        new long[] { 0, 0, 0, 0, 0, 1 },
        new long[] { r3, 0, r3, 0, 0, r3 },
    };
    class Matrix
    {
        public static int mod = 1_000_000_007;
        // 行列の累乗
        public static long[][] Pow(long[][] m, long k)
        {
            var multi = m;
            var r = new long[m.Length][];
            for (var i = 0; i < m.Length; ++i)
            {
                r[i] = new long[m.Length];
                r[i][i] = 1;
            }
            while (k > 0)
            {
                if ((k & 1) == 1) r = Mul(r, multi);
                multi = Mul(multi, multi);
                k >>= 1;
            }
            return r;
        }
        // 行列の積
        public static long[][] Mul(long[][] x, long[][] y)
        {
            var r = new long[x.Length][];
            for (var i = 0; i < x.Length; ++i) r[i] = new long[y[0].Length];
            for (var i = 0; i < x.Length; ++i) for (var k = 0; k < x[0].Length; ++k)
            {
                for (var j = 0; j < y[0].Length; ++j) r[i][j] = (r[i][j] + x[i][k] * y[k][j]) % mod;
            }
            return r;
        }
    }
}
0