結果

問題 No.434 占い
ユーザー ytftytft
提出日時 2021-03-22 14:25:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,512 bytes
コンパイル時間 1,964 ms
コンパイル使用メモリ 174,300 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-03 03:49:51
合計ジャッジ時間 4,028 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 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 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 9 ms
5,376 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 17 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 67 ms
5,376 KB
testcase_16 AC 62 ms
5,376 KB
testcase_17 AC 48 ms
5,376 KB
testcase_18 AC 51 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 147 ms
5,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 60 ms
5,376 KB
testcase_25 AC 68 ms
5,376 KB
testcase_26 AC 42 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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]+a[i+1])%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;
    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]);
        }
        cout<<(temp==0?0:(temp+8)%9+1)<<endl;
    }
}
0