結果

問題 No.435 占い(Extra)
ユーザー cielciel
提出日時 2016-10-18 01:19:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 827 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 61,824 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 02:44:26
合計ジャッジ時間 4,057 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 RE -
testcase_13 AC 14 ms
5,376 KB
testcase_14 AC 14 ms
5,376 KB
testcase_15 AC 15 ms
5,376 KB
testcase_16 AC 19 ms
5,376 KB
testcase_17 AC 65 ms
5,376 KB
testcase_18 RE -
testcase_19 AC 15 ms
5,376 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 109 ms
5,376 KB
testcase_23 AC 106 ms
5,376 KB
testcase_24 AC 119 ms
5,376 KB
testcase_25 AC 159 ms
5,376 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 4 ms
5,376 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 112 ms
5,376 KB
testcase_34 AC 131 ms
5,376 KB
testcase_35 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <tuple>
#include <algorithm>
#include <cstdio>
using namespace std;

vector<int> I={-1,1,5,-1,7,2,-1,4,8};
vector<pair<char,int> > F={{1,0}};
pair<int,int> z(int n){
	int r=0;
	for(;n%3==0;n/=3)r++;
	return {n,r};
}
int comb(int n,int k){
	char k0,k1,k2;
	int z0,z1,z2;
	tie(k0,z0)=F[n];
	tie(k1,z1)=F[k];
	tie(k2,z2)=F[n-k];
	int z=z0-z1-z2,r=(int)k0*I[k1]*I[k2]%9;
	return z==0 ? r : z==1 ? r*3%9 : 0;
}
int main(){
	for(int i=1;i<=100000;i++){
		char k0;
		int z0,z1,k1;
		tie(k0,z0)=F[i-1];
		tie(k1,z1)=z(i);
		F.emplace_back(k0*k1%9,z0+z1);
	}
	int T,n,x,a,b,m,r;
	for(scanf("%d",&T);T--;){
		scanf("%d%d%d%d%d",&n,&x,&a,&b,&m);
		bool f=true;
		r=0;
		for(int i=0;i<n;i++){
			int c=x%10;
			r=(r+c*comb(n-1,i))%9;
			if(c)f=false;
			x=((x^a)+b)%m;
		}
		printf("%d\n",r!=0||f ? r : 9);
	}
}
0