結果
問題 | No.613 Solitude by the window |
ユーザー | 紙ぺーぱー |
提出日時 | 2017-12-13 12:44:04 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 8,459 bytes |
コンパイル時間 | 1,046 ms |
コンパイル使用メモリ | 113,536 KB |
実行使用メモリ | 18,176 KB |
最終ジャッジ日時 | 2024-05-08 07:47:36 |
合計ジャッジ時間 | 2,361 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 23 ms
17,792 KB |
testcase_01 | AC | 23 ms
17,408 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 22 ms
17,792 KB |
testcase_18 | AC | 23 ms
17,920 KB |
testcase_19 | WA | - |
testcase_20 | AC | 24 ms
17,536 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; using Debug = System.Diagnostics.Debug; //using System.Numerics; //using static System.Math; using Number = ModInt; namespace Program { public class Solver { public void Solve() { long n = rl; ModInt.Mod = ri; if (ModInt.Mod == 2) { Console.WriteLine(0); return; } //naive(n, ModInt.Mod + 1); //for (int _ = 1; _ < 1000; _++) for (int m = Math.Max(1, ModInt.Mod - 50); m < ModInt.Mod + 50; m++) { //n = _; //naive(2, n, ModInt.Mod); var mat = new Matrix(2, 2); mat[0, 0] = 4; mat[0, 1] = -1; mat[1, 0] = 1; var tmp = Matrix.Pow(mat, m); if (tmp[0, 0].num == 1 && tmp[0, 1].num == 0 && tmp[1, 0].num == 0 && tmp[1, 1].num == 1) { var nmod = ModInt.Mod; Swap(ref nmod, ref ModInt.Mod); var k = ModInt.Pow(2, n).num; var res = Matrix.Pow(mat, k); var ans = (res[1, 0] * 4 + res[1, 1] * 2) - 2; Console.WriteLine(ans); return; } } } const long INF = 1L << 60; int[] dx = { 1, 0, -1, 0 }; int[] dy = { 0, 1, 0, -1 }; //* int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } //*/ public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie.Select(x => x.ToString()).ToArray()); //return string.Join(st, ie); } static public void Main() { Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Program.Solver(); solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.Globalization; using System.IO; using System.Text; public class Printer: StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion #region Matrix public class Matrix { int row, col; public Number[] mat; public Number this[int r, int c] { get { return mat[r * col + c]; } set { mat[r * col + c] = value; } } public Matrix(int r, int c) { row = r; col = c; mat = new Number[row * col]; } public static Matrix operator +(Matrix l, Matrix r) { check(l, r); var ret = new Matrix(l.row, l.col); for (int i = 0; i < l.row; i++) for (int j = 0; j < l.col; j++) ret.mat[i * ret.col + j] = l.mat[i * l.col + j] + r.mat[i * r.col + j]; return ret; } public static Matrix operator *(Matrix l, Matrix r) { checkMul(l, r); var ret = new Matrix(l.row, r.col); for (int i = 0; i < l.row; i++) for (int k = 0; k < l.col; k++) for (int j = 0; j < r.col; j++) ret.mat[i * r.col + j] = (ret.mat[i * r.col + j] + l.mat[i * l.col + k] * r.mat[k * r.col + j]); return ret; } public static Matrix Pow(Matrix m, long n) { var ret = new Matrix(m.row, m.col); for (int i = 0; i < m.row; i++) ret.mat[i * m.col + i] = 1; for (; n > 0; m *= m, n >>= 1) if ((n & 1) == 1) ret = ret * m; return ret; } public static Matrix Trans(Matrix m) { var ret = new Matrix(m.col, m.row); for (int i = 0; i < m.row; i++) for (int j = 0; j < m.col; j++) ret.mat[j * m.col + i] = m.mat[i * m.col + j]; return ret; } [System.Diagnostics.Conditional("DEBUG")] static private void check(Matrix a, Matrix b) { if (a.row != b.row || a.col != b.col) throw new Exception("row and col have to be same."); } [System.Diagnostics.Conditional("DEBUG")] static private void checkMul(Matrix a, Matrix b) { if (a.col != b.row) throw new Exception("row and col have to be same."); } public Number[][] Items { get { var a = new Number[row][]; for (int i = 0; i < row; i++) { a[i] = new Number[col]; for (int j = 0; j < col; j++) a[i][j] = mat[i * col + j]; } return a; } } public override string ToString() { return string.Format("{0}*{1}", row, col); } } #endregion //剰余環 #region ModInt public struct ModInt { public static int Mod = (int)1e9 + 7; public int num; public ModInt(int n) { num = n; } public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt((int)(l.num * (long)r.num % Mod)); } public static implicit operator ModInt(int n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt((int)n); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } public static ModInt Pow(int v, long k) { int ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = (int)(v * (long)v % Mod)) if ((k & 1) == 1) ret = (int)(ret * (long)v % Mod); return new ModInt(ret); } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion struct cmp: IComparer<Number[]> { public int Compare(Number[] x, Number[] y) { for (int i = 0; i < x.Length; i++) if (x[i].num < y[i].num) return -1; else if (x[i].num > y[i].num) return 1; return 0; } } #region SortedMap<K,V> public class SortedMap<K, V>: SortedDictionary<K, V> { public SortedMap() { } public SortedMap(IComparer<K> cmp) : base(cmp) { } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = default(V); } set { base[i] = value; } } } #endregion