結果
| 問題 |
No.434 占い
|
| コンテスト | |
| ユーザー |
ytft
|
| 提出日時 | 2021-03-22 13:30:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,098 bytes |
| コンパイル時間 | 2,154 ms |
| コンパイル使用メモリ | 174,872 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-11-23 23:46:11 |
| 合計ジャッジ時間 | 27,232 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 RE * 1 |
| other | AC * 12 WA * 1 RE * 7 TLE * 7 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
vector<int> merge(vector<int> a,vector<int> b,int MOD){
int A=a.size(),B=b.size();
vector<int> ret(A+B-1);
for(int i=0;i<A+B-1;i++){
for(int j=max(0,i+1-B);j<min(A,i+1);j++){
ret[i]=(ret[i]+a[j]*b[j-i+B-1])%MOD;
}
}
return ret;
}
vector<int> C(int step,int MOD){
vector<int> two;
while(step>0){
two.push_back(step%2);
step=step>>1;
}
int M=two.size();
vector<vector<int>> temp(M,vector<int>());
temp[0]={1,1};
for(int i=1;i<M;i++){
temp[i]=merge(temp[i-1],temp[i-1],MOD);
}
vector<int> cur;
cur={1};
for(int i=0;i<M;i++){
if(!two[i]){
continue;
}
cur=merge(cur,temp[i],MOD);
}
return cur;
}
int main(){
int T;
cin>>T;
string S;
vector<int> c;
int temp;
for(int i=0;i<T;i++){
cin>>S;
c=C(S.size()-1,9);
temp=0;
for(int i=0;i<S.size();i++){
temp=(temp+(S[i]-'0')*c[i])%9;
}
cout<<(temp+8)%9+1<<endl;
}
}
ytft