結果
| 問題 |
No.435 占い(Extra)
|
| コンテスト | |
| ユーザー |
ytft
|
| 提出日時 | 2021-03-22 14:54:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,643 bytes |
| コンパイル時間 | 2,037 ms |
| コンパイル使用メモリ | 173,244 KB |
| 実行使用メモリ | 90,124 KB |
| 最終ジャッジ日時 | 2024-11-24 01:13:01 |
| 合計ジャッジ時間 | 54,719 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 MLE * 1 |
| other | AC * 14 WA * 1 TLE * 15 MLE * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
vector<int> merge(vector<int> a,int p,int MOD){
if(p==0){
int N=a.size()+1;
vector<int> ret(N,1);
for(int i=1;i<N-1;i++){
ret[i]=(a[i-1]+a[i])%MOD;
}
return ret;
}
int A=a.size(),N=A+pow(3,p);
vector<int> ret(N);
for(int i=0;i<N;i++){
if(0<=i-pow(3,p)+0 && i-pow(3,p)+0<a.size()){
ret[i]+=a[i-pow(3,p)+0];
}
if(0<=i-pow(3,p)+pow(3,p-1) && i-pow(3,p)+pow(3,p-1)<a.size()){
ret[i]+=a[i-pow(3,p)+pow(3,p-1)]*3;
}
if(0<=i-pow(3,p)+pow(3,p-1)*2 && i-pow(3,p)+pow(3,p-1)*2<a.size()){
ret[i]+=a[i-pow(3,p)+pow(3,p-1)*2]*3;
}
if(0<=i-pow(3,p)+pow(3,p-1)*3 && i-pow(3,p)+pow(3,p-1)*3<a.size()){
ret[i]+=a[i-pow(3,p)+pow(3,p-1)*3];
}
ret[i]%=MOD;
}
return ret;
}
vector<int> C(int step,int MOD){
vector<int> three;
while(step>0){
three.push_back(step%3);
step=step/3;
}
vector<int> cur={1};
for(int i=0;i<three.size();i++){
for(int j=0;j<three[i];j++){
cur=merge(cur,i,MOD);
}
}
return cur;
}
int main(){
int T;
cin>>T;
long long n,x,a,b,m;
int temp=0;
vector<int> c;
bool flg;
for(int i=0;i<T;i++){
cin>>n>>x>>a>>b>>m;
c=C(n-1,9);
temp=0;
temp=(temp+c[0]*(x%10))%9;
flg=(x==0);
for(int j=1;j<n;j++){
x=((x^a)+b)%m;
if(x!=0)flg=false;
temp=(temp+c[j]*(x%10))%9;
}
cout<<(flg?0:(temp+8)%9+1)<<endl;
}
}
ytft