結果

問題 No.840 ほむほむほむら
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-01-30 07:07:35
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,075 ms / 4,000 ms
コード長 3,497 bytes
コンパイル時間 3,182 ms
コンパイル使用メモリ 107,488 KB
実行使用メモリ 23,312 KB
最終ジャッジ日時 2023-10-14 08:08:28
合計ジャッジ時間 12,278 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
21,124 KB
testcase_01 AC 63 ms
23,168 KB
testcase_02 AC 78 ms
21,184 KB
testcase_03 AC 193 ms
21,148 KB
testcase_04 AC 59 ms
21,120 KB
testcase_05 AC 59 ms
21,132 KB
testcase_06 AC 64 ms
21,224 KB
testcase_07 AC 102 ms
23,176 KB
testcase_08 AC 297 ms
23,244 KB
testcase_09 AC 67 ms
23,228 KB
testcase_10 AC 61 ms
21,148 KB
testcase_11 AC 66 ms
21,072 KB
testcase_12 AC 135 ms
19,128 KB
testcase_13 AC 668 ms
23,108 KB
testcase_14 AC 142 ms
21,132 KB
testcase_15 AC 61 ms
19,152 KB
testcase_16 AC 70 ms
23,272 KB
testcase_17 AC 199 ms
21,248 KB
testcase_18 AC 1,070 ms
23,200 KB
testcase_19 AC 1,075 ms
23,232 KB
testcase_20 AC 60 ms
21,272 KB
testcase_21 AC 59 ms
21,196 KB
testcase_22 AC 69 ms
21,124 KB
testcase_23 AC 1,072 ms
23,312 KB
testcase_24 AC 71 ms
21,136 KB
testcase_25 AC 59 ms
23,096 KB
testcase_26 AC 72 ms
21,256 KB
testcase_27 AC 903 ms
23,156 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=998244353;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		var n=s[1];
		var m=(int)Pow(n,3);
		var g=new long[m][];
		var b=new long[m][];
		for(int i = 0;i<n;i++) {
			for(int j = 0;j<n;j++) {
				for(int k = 0;k<n;k++) {
					int z=i+j*n+k*n*n;
					g[z]=new long[m];
					g[z][((i+n-1)%n)+j*n+k*n*n]++;
					g[z][i+((j+n-i)%n)*n+k*n*n]++;
					g[z][i+j*n+((k+n-j)%n)*n*n]++;
					b[z]=new long[1];
				}
			}
		}
		b[0][0]=1;
		long ans=0;
		var c=Mp(b,g,s[0]);//n回
		for(int i = 0;i<n;i++) {
			for(int j = 0;j<n;j++) {ans=(ans+c[i+j*n][0])%mod;}
		}
		Console.WriteLine(ans);
	}
	static long[][] Mp(long[][] r,long[][] x,long e){
		while(e>0){
			if((e&1)>0){r=Mm(x,r);}
			x=Mm(x,x);
			e>>=1;
		}
		return r;
	}
	static long[][] Mm(long[][] a,long[][] b){
		long[][] q=new long[a.Length][];
		for(int j=0;j<a.Length;j++){
			q[j]=new long [b[0].Length];
			for(int i=0;i<b[0].Length;i++){
				for(int k=0;k<a.Length;k++){q[j][i]=(q[j][i]+a[j][k]*b[k][i])%mod;}
			}
		}
		return q;
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<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;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
0