結果
問題 | No.2443 特殊線形群の標準表現 |
ユーザー | kakel-san |
提出日時 | 2023-08-25 23:09:26 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 906 ms / 3,000 ms |
コード長 | 5,180 bytes |
コンパイル時間 | 1,265 ms |
コンパイル使用メモリ | 118,816 KB |
実行使用メモリ | 105,184 KB |
最終ジャッジ日時 | 2024-06-06 17:57:49 |
合計ジャッジ時間 | 8,781 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
19,200 KB |
testcase_01 | AC | 33 ms
19,328 KB |
testcase_02 | AC | 33 ms
19,200 KB |
testcase_03 | AC | 34 ms
19,200 KB |
testcase_04 | AC | 34 ms
19,328 KB |
testcase_05 | AC | 33 ms
19,200 KB |
testcase_06 | AC | 34 ms
19,200 KB |
testcase_07 | AC | 34 ms
19,200 KB |
testcase_08 | AC | 34 ms
19,200 KB |
testcase_09 | AC | 34 ms
19,328 KB |
testcase_10 | AC | 34 ms
19,328 KB |
testcase_11 | AC | 33 ms
18,816 KB |
testcase_12 | AC | 35 ms
19,456 KB |
testcase_13 | AC | 42 ms
21,856 KB |
testcase_14 | AC | 114 ms
30,976 KB |
testcase_15 | AC | 900 ms
105,064 KB |
testcase_16 | AC | 890 ms
105,184 KB |
testcase_17 | AC | 894 ms
104,820 KB |
testcase_18 | AC | 903 ms
105,068 KB |
testcase_19 | AC | 906 ms
104,932 KB |
testcase_20 | AC | 866 ms
105,072 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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, 10); 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(10), r.Next(10) }; } // 愚直解 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] %= 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] % b + b) % b, (z[1][0] % b + b) % b }; } return string.Join("\n", ans.Select(ai => string.Join(" ", ai))); } static long[][] Rev1(long[][] m) { return new long[][] { new long[] { m[1][1], - m[0][1] }, new long[] { - m[1][0], 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][]; 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; } } }