結果

問題 No.569 3 x N グリッドのパスの数
コンテスト
ユーザー 👑 kakel-san
提出日時 2026-11-08 23:52:37
言語 C#
(.NET 10.0.403 + ACL)
コンパイル:
dotnet_c
実行:
/usr/bin/dotnet_wrap
結果
AC  
実行時間 46 ms / 2,000 ms
+ 814µs
コード長 6,289 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 14,351 ms
コンパイル使用メモリ 170,368 KB
実行使用メモリ 31,872 KB
最終ジャッジ日時 2026-11-08 23:52:59
合計ジャッジ時間 11,542 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 60
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (236 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net10.0/main.dll
  main -> /home/judge/data/code/bin/Release/net10.0/publish/

ソースコード

diff #
raw source code

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

class Program
{
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = long.Parse(ReadLine());
        var a = new long[][] { [1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0] };
        var x = new long[][]
        {
            [1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1],
            [1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1],
            [1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0],
            [1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0],
            [1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0],
            [0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0],
            [1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0],
            [0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0],
            [1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0],
            [0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1],
            [1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0],
            [0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1]
        };
        var b = Matrix.Mul(a, Matrix.Pow(x, n - 1));
        WriteLine((b[0][0] + b[0][1] + b[0][2] + b[0][3] + b[0][4] + b[0][6] + b[0][8] + b[0][10]) % mod);
    }
    // visualizer
    static void OutputLeft(int id, List<char>[] text)
    {
        if (new int[] { 0, 4, 6, 8 }.Contains(id))
        {
            text[0].Add('-');
            text[0].Add('-');
        }
        if (new int[] { 1, 10 }.Contains(id))
        {
            text[2].Add('-');
            text[2].Add('-');
        }
        if (new int[] { 2, 5 }.Contains(id))
        {
            text[4].Add('-');
            text[4].Add('-');
        }
        if (new int[] { 3, 7, 9, 11 }.Contains(id))
        {
            text[6].Add('-');
            text[6].Add('-');
        }
        if (new int[] { 5, 7 }.Contains(id))
        {
            text[0].Add('+');
            text[0].Add('-');
            text[1].Add('|');
            text[2].Add('+');
            text[2].Add('-');
        }
        if (id == 9)
        {
            text[0].Add('+');
            text[0].Add('-');
            text[1].Add('|');
            text[2].Add('|');
            text[3].Add('|');
            text[4].Add('+');
            text[4].Add('-');
        }
        if (id == 4 || id == 11)
        {
            text[2].Add('+');
            text[2].Add('-');
            text[3].Add('|');
            text[4].Add('+');
            text[4].Add('-');
        }
        if (id == 6)
        {
            text[2].Add('+');
            text[2].Add('-');
            text[3].Add('|');
            text[4].Add('|');
            text[5].Add('|');
            text[6].Add('+');
            text[6].Add('-');
        }
        if (id == 8 || id == 10)
        {
            text[4].Add('+');
            text[4].Add('-');
            text[5].Add('|');
            text[6].Add('+');
            text[6].Add('-');
        }
        for (var i = 0; i < 7; ++i)
        {
            while (text[i].Count < 2) text[i].Add(' ');
            if (i % 2 == 0) text[i].Add('O');
            else text[i].Add(' ');
        }
    }
    static void OutputRight(int id, List<char>[] text)
    {
        if (new int[] { 0, 4, 6, 8 }.Contains(id))
        {
            text[0].Add('-');
            text[0].Add('-');
        }
        if (new int[] { 1, 10 }.Contains(id))
        {
            text[2].Add('-');
            text[2].Add('-');
        }
        if (new int[] { 2, 5 }.Contains(id))
        {
            text[4].Add('-');
            text[4].Add('-');
        }
        if (new int[] { 3, 7, 9, 11 }.Contains(id))
        {
            text[6].Add('-');
            text[6].Add('-');
        }
        if (new int[] { 5, 7 }.Contains(id))
        {
            text[0].Add('-');
            text[0].Add('+');
            text[1].Add(' ');
            text[1].Add('|');
            text[2].Add('-');
            text[2].Add('+');
        }
        if (id == 9)
        {
            text[0].Add('-');
            text[0].Add('+');
            text[1].Add(' ');
            text[1].Add('|');
            text[2].Add(' ');
            text[2].Add('|');
            text[3].Add(' ');
            text[3].Add('|');
            text[4].Add('-');
            text[4].Add('+');
        }
        if (id == 4 || id == 11)
        {
            text[2].Add('-');
            text[2].Add('+');
            text[3].Add(' ');
            text[3].Add('|');
            text[4].Add('-');
            text[4].Add('+');
        }
        if (id == 6)
        {
            text[2].Add('-');
            text[2].Add('+');
            text[3].Add(' ');
            text[3].Add('|');
            text[4].Add(' ');
            text[4].Add('|');
            text[5].Add(' ');
            text[5].Add('|');
            text[6].Add('-');
            text[6].Add('+');
        }
        if (id == 8 || id == 10)
        {
            text[4].Add('-');
            text[4].Add('+');
            text[5].Add(' ');
            text[5].Add('|');
            text[6].Add('-');
            text[6].Add('+');
        }
    }
    static int mod = 1_000_000_007;
    class Matrix
    {
        // 行列の累乗
        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