結果

問題 No.2443 特殊線形群の標準表現
ユーザー kakel-sankakel-san
提出日時 2023-08-25 23:01:34
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 5,293 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 110,336 KB
実行使用メモリ 105,568 KB
最終ジャッジ日時 2024-06-06 17:46:55
合計ジャッジ時間 7,418 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
19,072 KB
testcase_01 AC 30 ms
19,328 KB
testcase_02 AC 28 ms
19,200 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 28 ms
19,200 KB
testcase_09 WA -
testcase_10 AC 29 ms
19,072 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    static long[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
        // Test();
    }
    static void Test()
    {
        var r = new Random();
        var count = 0;
        while (true)
        {
            var n = 100;
            var b = r.Next(1, 1000000000);
            var q = 1;
            var mxlist = new long[n][][];
            for (var i = 0; i < n; ++i) mxlist[i] = Make(r);
            var query = new long[q][];
            for (var i = 0; i < q; ++i)
            {
                var s = r.Next(1, n + 1);
                var t = r.Next(1, n + 1);
                query[i] = new long[] { Math.Min(s, t), Math.Max(s, t), r.Next(1000000000), r.Next(1000000000) };
            }
            // 愚直解
            var s1 = All(n, b, q, mxlist, query);
            // 作成解
            var s2 = Linear(n, b, q, mxlist, query);
            if (s1 != s2)
            {
                WriteLine($"{n} {b} {q}");
                for (var i = 0; i < n; ++i) WriteLine(string.Join("\n", mxlist[i].Select(m => string.Join(" ", m))));
                WriteLine(string.Join("\n", query.Select(qi => string.Join(" ", qi))));
                WriteLine(s1);
                WriteLine(s2);
                return;
            }
            ++count;
            if (count % 1000 == 0) WriteLine(count);
        }
    }
    static long[][] Make(Random r)
    {
        while (true)
        {
            var ans = new long[][] { new long[] { r.Next(-10, 10), r.Next(-10, 10) }, new long[] { r.Next(-10, 10), r.Next(-10, 10) } };
            if (ans[0][0] * ans[1][1] - ans[0][1] * ans[1][0] == 1) return ans;
        }
    }
    static string All(long n, long b, long q, long[][][] mxlist, long[][] query)
    {
        Matrix.mod = b;
        var ans = new long[q][];
        for (var i = 0; i < q; ++i)
        {
            var x = new long[][] { new long[] { query[i][2] }, new long[] { query[i][3] } };
            for (var j = query[i][0] + 1; j <= query[i][1]; ++j)
            {
                x = Matrix.Mul(mxlist[j - 1], x);
            }
            ans[i] = new long[] { (x[0][0] % b + b) % b, (x[1][0] % b + b) % b };
        }
        return string.Join("\n", ans.Select(ai => string.Join(" ", ai)));
    }
    static void Solve()
    {
        var c = NList;
        var (n, b, q) = (c[0], c[1], c[2]);
        var mxlist = new long[n][][];
        for (var i = 0; i < n; ++i)
        {
            mxlist[i] = NArr(2);
        }
        var query = NArr(q);
        WriteLine(Linear(n, b, q, mxlist, query));
    }
    static string Linear(long n, long b, long q, long[][][] _mxlist, long[][] query)
    {
        var mxlist = new long[n][][];
        for (var i = 0; i < n; ++i)
        {
            mxlist[i] = new long[2][];
            mxlist[i][0] = new long[] { _mxlist[i][0][0], _mxlist[i][0][1] };
            mxlist[i][1] = new long[] { _mxlist[i][1][0], _mxlist[i][1][1] };
            for (var j = 0; j < 2; ++j) for (var k = 0; k < 2; ++k)
            {
                mxlist[i][j][k] = (mxlist[i][j][k] % b + b) % b;
            }
        }
        Matrix.mod = b;

        var mullist = new long[n + 1][][];
        mullist[0] = new long[][] { new long[] { 1, 0 }, new long[] { 0, 1 } };
        for (var i = 0; i < n; ++i)
        {
            mullist[i + 1] = Matrix.Mul(mxlist[i], mullist[i]);
        }
        var revlist = new long[n + 1][][];
        revlist[0] = new long[][] { new long[] { 1, 0 }, new long[] { 0, 1 } };
        for (var i = 0; i < n; ++i)
        {
            revlist[i + 1] = Matrix.Mul(revlist[i], Rev1(mxlist[i]));
        }
        var ans = new long[q][];
        for (var i = 0; i < q; ++i)
        {
            var l = query[i][0];
            var r = query[i][1];
            var x = new long[][] { new long[] { query[i][2] }, new long[] { query[i][3] } };
            var z = Matrix.Mul(Matrix.Mul(mullist[r], revlist[l]), x);
            ans[i] = new long[] { z[0][0], z[1][0] };
        }
        return string.Join("\n", ans.Select(ai => string.Join(" ", ai)));
    }
    static long[][] Rev1(long[][] m)
    {
        return new long[][] {
            new long[] { m[1][1], (Matrix.mod - m[0][1]) % Matrix.mod },
            new long[] { (Matrix.mod - m[1][0]) % Matrix.mod, m[0][0] }};
    }
    class Matrix
    {
        public static long mod = 1_000_000_007;
        public static long[][] Mul(long[][] x, long[][] y)
        {
            var r = new long[x.Length][];
            checked {
            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