結果

問題 No.435 占い(Extra)
ユーザー sigma425sigma425
提出日時 2017-09-14 03:59:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 438 ms / 2,000 ms
コード長 1,369 bytes
コンパイル時間 1,277 ms
コンパイル使用メモリ 158,828 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 02:57:09
合計ジャッジ時間 5,367 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 15 ms
5,376 KB
testcase_13 AC 14 ms
5,376 KB
testcase_14 AC 14 ms
5,376 KB
testcase_15 AC 18 ms
5,376 KB
testcase_16 AC 46 ms
5,376 KB
testcase_17 AC 323 ms
5,376 KB
testcase_18 AC 14 ms
5,376 KB
testcase_19 AC 14 ms
5,376 KB
testcase_20 AC 127 ms
5,376 KB
testcase_21 AC 127 ms
5,376 KB
testcase_22 AC 128 ms
5,376 KB
testcase_23 AC 131 ms
5,376 KB
testcase_24 AC 159 ms
5,376 KB
testcase_25 AC 438 ms
5,376 KB
testcase_26 AC 127 ms
5,376 KB
testcase_27 AC 129 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 129 ms
5,376 KB
testcase_30 AC 127 ms
5,376 KB
testcase_31 AC 104 ms
5,376 KB
testcase_32 AC 112 ms
5,376 KB
testcase_33 AC 147 ms
5,376 KB
testcase_34 AC 266 ms
5,376 KB
testcase_35 AC 131 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:63:35: warning: ‘b’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |                                 Y *= b;
      |                                 ~~^~~~

ソースコード

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 %= 9;
				Y *= a;
				Y %= 9;
			}
			{
				int a = i+1;
				while(a%3==0){
					a/=3;
					X--;
				}
				a %= 9;
				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