結果

問題 No.435 占い(Extra)
ユーザー sigma425sigma425
提出日時 2017-09-14 03:59:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,369 bytes
コンパイル時間 1,062 ms
コンパイル使用メモリ 160,344 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 02:57:02
合計ジャッジ時間 4,579 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

int main(){
	int T;
	cin>>T;
	rep(tq,T){
		int N,x,a,b,m;
		cin>>N>>x>>a>>b>>m;
		int res = 0;
		int X = 0, Y = 1;	// C = 3^X * Y
		bool all0 = 1;
		rep(i,N){
			int p = x%10;
			if(p){
				all0 = 0;
			}
			if(X==0){
				res += p*Y;
			}else if(X==1){
				res += p*3*Y;
			}
			res %= 9;

			x = ((x^a)+b)%m;
//			C = C*(N-1-i)/(i+1);
			if(i==N-1) break;
			{
				int a = N-1-i;
				while(a%3==0){
					a/=3;
					X++;
				}
				a %= 3;
				Y *= a;
				Y %= 9;
			}
			{
				int a = i+1;
				while(a%3==0){
					a/=3;
					X--;
				}
				a %= 3;
				int b;
				if(a==1) b = 1;
				if(a==2) b = 5;
				if(a==4) b = 7;
				if(a==5) b = 2;
				if(a==7) b = 4;
				if(a==8) b = 8;
				Y *= b;
				Y %= 9;
			}
		}
		if(!all0 && res==0) res = 9;
		cout<<res<<endl;
	}
}
0