結果

問題 No.658 テトラナッチ数列 Hard
ユーザー %20%20
提出日時 2018-03-02 23:53:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 740 bytes
コンパイル時間 2,275 ms
コンパイル使用メモリ 199,996 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 02:09:00
合計ジャッジ時間 3,979 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 110 ms
4,384 KB
testcase_05 AC 112 ms
4,380 KB
testcase_06 AC 118 ms
4,376 KB
testcase_07 AC 120 ms
4,376 KB
testcase_08 AC 125 ms
4,380 KB
testcase_09 AC 142 ms
4,380 KB
testcase_10 AC 142 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:27:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   27 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int Z[4][4];

void f(int a[4][4]){
	int r[4][4];
	for(int y=0;y<4;++y){
		for(int x=0;x<4;++x){
			r[y][x]=0;
		}
	}
	for(int y=0;y<4;++y){
		for(int x=0;x<4;++x){
			for(int i=0;i<4;++i){
				(r[y][x]+=Z[y][i]*a[i][x])%=17;
			}
		}
	}
	for(int y=0;y<4;++y){
		for(int x=0;x<4;++x){
			Z[y][x]=r[y][x];
		}
	}
}

main(){
	int Q;
	scanf("%d",&Q);
	for(int i=0;i<Q;++i){
		long long n;
		scanf("%lld",&n);
		--n;
		for(int y=0;y<4;++y){
			for(int x=0;x<4;++x){
				Z[y][x]=x==y;
			}
		}
		for(int i=60;i--;){
			f(Z);
			if(n>>i&1){
				int a[4][4];
				for(int y=0;y<4;++y){
					for(int x=0;x<4;++x){
						a[y][x]=y==0|y-1==x;
					}
				}
				f(a);
			}
		}
		printf("%d\n",Z[3][0]);
	}
}
0