結果

問題 No.435 占い(Extra)
ユーザー cielciel
提出日時 2016-10-18 01:26:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 841 bytes
コンパイル時間 616 ms
コンパイル使用メモリ 62,508 KB
実行使用メモリ 47,624 KB
最終ジャッジ日時 2024-04-17 02:46:02
合計ジャッジ時間 7,335 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
44,196 KB
testcase_01 AC 100 ms
44,452 KB
testcase_02 AC 99 ms
44,328 KB
testcase_03 AC 96 ms
44,452 KB
testcase_04 AC 94 ms
44,196 KB
testcase_05 AC 94 ms
44,408 KB
testcase_06 AC 95 ms
44,200 KB
testcase_07 AC 95 ms
44,328 KB
testcase_08 AC 96 ms
44,452 KB
testcase_09 AC 96 ms
44,200 KB
testcase_10 WA -
testcase_11 AC 96 ms
44,196 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 110 ms
44,452 KB
testcase_15 AC 109 ms
44,324 KB
testcase_16 AC 115 ms
44,452 KB
testcase_17 AC 165 ms
44,200 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 213 ms
44,192 KB
testcase_24 AC 219 ms
44,324 KB
testcase_25 AC 272 ms
44,200 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 95 ms
44,192 KB
testcase_29 WA -
testcase_30 AC 216 ms
44,164 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 214 ms
44,320 KB
testcase_34 AC 240 ms
44,452 KB
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

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<char> Fk={1};
vector<short> Fz={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=Fk[n],k1=Fk[k],k2=Fk[n-k];
	short z0=Fz[n],z1=Fz[k],z2=Fz[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<=10000000;i++){
		char k0=Fk[i-1];
		short z0=Fz[i-1];
		int z1,k1;
		tie(k1,z1)=z(i);
		Fk.push_back(k0*k1%9);
		Fz.push_back(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