結果

問題 No.434 占い
ユーザー ytftytft
提出日時 2021-03-22 14:40:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,738 bytes
コンパイル時間 1,827 ms
コンパイル使用メモリ 172,704 KB
実行使用メモリ 4,644 KB
最終ジャッジ日時 2023-08-15 17:01:33
合計ジャッジ時間 5,394 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 RE -
testcase_20 RE -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

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-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;
    string S;
    vector<int> c;
    cout<<endl;
    int temp;
    for(int i=0;i<T;i++){
        cin>>S;
        c=C(S.size()-1,9);
        temp=0;
        for(int j=0;j<S.size();j++){
            if(S[i]!='0'){
                break;
            }
            if(j==S.size()-1){
                cout<<0<<endl;
                goto lab;
            }
        }
        for(int j=0;j<S.size();j++){
            temp+=(S[j]-'0')*c[j];
        }
        cout<<(temp+8)%9+1<<endl;
        lab:{}
    }
}
0