結果

問題 No.2017 Mod7 Parade
ユーザー 👑 kakel-sankakel-san
提出日時 2022-07-22 22:10:11
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 321 ms / 2,000 ms
コード長 2,009 bytes
コンパイル時間 1,320 ms
コンパイル使用メモリ 68,208 KB
実行使用メモリ 32,128 KB
最終ジャッジ日時 2023-09-17 10:22:12
合計ジャッジ時間 6,955 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
23,676 KB
testcase_01 AC 67 ms
21,564 KB
testcase_02 AC 64 ms
19,624 KB
testcase_03 AC 263 ms
31,164 KB
testcase_04 AC 200 ms
31,880 KB
testcase_05 AC 166 ms
29,332 KB
testcase_06 AC 285 ms
29,432 KB
testcase_07 AC 94 ms
26,008 KB
testcase_08 AC 190 ms
29,648 KB
testcase_09 AC 114 ms
26,208 KB
testcase_10 AC 191 ms
27,744 KB
testcase_11 AC 239 ms
30,644 KB
testcase_12 AC 219 ms
28,068 KB
testcase_13 AC 320 ms
32,028 KB
testcase_14 AC 321 ms
32,096 KB
testcase_15 AC 319 ms
32,028 KB
testcase_16 AC 319 ms
30,060 KB
testcase_17 AC 321 ms
32,128 KB
testcase_18 AC 297 ms
30,052 KB
testcase_19 AC 206 ms
27,980 KB
testcase_20 AC 65 ms
23,572 KB
権限があれば一括ダウンロードができます

ソースコード

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(int n) => Enumerable.Repeat(0, n).Select(_ => NList).ToArray();
    static void Main()
    {
        var k = NN;
        var map = NArr(k);

        var nexts = new int[10][];
        nexts[0] = new int[] { 0, 3, 6, 2, 5, 1, 4 };
        for (var i = 1; i < 7; ++i)
        {
            nexts[i] = new int[7];
            for (var j = 0; j < 7; ++j) nexts[i][j] = (nexts[i - 1][j] + 1) % 7;
        }
        var dbl = new List<int[]>[7];
        for (var i = 0; i < dbl.Length; ++i)
        {
            dbl[i] = new List<int[]>();
            dbl[i].Add((int[])nexts[i].Clone());
        }
        var mod = 1_000_000_007;
        var dp = new long[7];
        dp[0] = 1;
        for (var i = 0; i < k; ++i)
        {
            var next = (long[]) dp.Clone();
            var to = new int[] { 0, 1, 2, 3, 4, 5, 6 };
            var d = map[i][0] % 7;
            var l = map[i][1];
            var cnt = 0;
            while (l > 0)
            {
                if (cnt >= dbl[d].Count)
                {
                    var newarr = new int[7];
                    for (var j = 0; j < newarr.Length; ++j) newarr[j] = dbl[d][cnt - 1][dbl[d][cnt - 1][j]];
                    dbl[d].Add(newarr);
                }
                if (l % 2 == 1)
                {
                    for (var j = 0; j < to.Length; ++j) to[j] = dbl[d][cnt][to[j]];
                }
                ++cnt;
                l >>= 1;
            }
            for (var j = 0; j < to.Length; ++j) next[to[j]] = (next[to[j]] + dp[j]) % mod;
            dp = next;
        }
        var res = 0L;
        for (var i = 0; i < dp.Length; ++i) res = (res + dp[i] * i) % mod;
        WriteLine(res);
    }

}
0