結果

問題 No.434 占い
ユーザー latte0119latte0119
提出日時 2016-10-15 01:07:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 1,431 bytes
コンパイル時間 1,401 ms
コンパイル使用メモリ 146,404 KB
実行使用メモリ 8,488 KB
最終ジャッジ日時 2023-08-14 12:43:10
合計ジャッジ時間 2,922 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,016 KB
testcase_01 AC 6 ms
8,104 KB
testcase_02 AC 6 ms
8,172 KB
testcase_03 AC 6 ms
8,080 KB
testcase_04 AC 6 ms
8,104 KB
testcase_05 AC 6 ms
8,060 KB
testcase_06 AC 8 ms
8,040 KB
testcase_07 AC 6 ms
8,120 KB
testcase_08 AC 6 ms
8,116 KB
testcase_09 AC 6 ms
8,176 KB
testcase_10 AC 7 ms
8,072 KB
testcase_11 AC 7 ms
8,020 KB
testcase_12 AC 19 ms
8,028 KB
testcase_13 AC 7 ms
8,128 KB
testcase_14 AC 6 ms
8,020 KB
testcase_15 AC 8 ms
8,192 KB
testcase_16 AC 8 ms
8,096 KB
testcase_17 AC 8 ms
8,116 KB
testcase_18 AC 11 ms
8,064 KB
testcase_19 AC 22 ms
8,092 KB
testcase_20 AC 137 ms
8,060 KB
testcase_21 AC 8 ms
8,168 KB
testcase_22 AC 8 ms
8,160 KB
testcase_23 AC 6 ms
8,344 KB
testcase_24 AC 8 ms
8,056 KB
testcase_25 AC 8 ms
8,488 KB
testcase_26 AC 7 ms
8,116 KB
testcase_27 AC 9 ms
8,084 KB
testcase_28 AC 10 ms
8,064 KB
testcase_29 AC 27 ms
8,068 KB
testcase_30 AC 111 ms
8,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int SIZE=300000;
int fact[SIZE],cnt[SIZE];
int inv[9];

void solve(){
    string S;
    cin>>S;

    if(count(all(S),'0')==S.size()){
        cout<<0<<endl;
        return;
    }

    int N=S.size()-1;
    int ans=0;
    for(int i=0;i<=N;i++){
        int t=cnt[N]-cnt[i]-cnt[N-i];
        int f=fact[N]*inv[fact[i]]*inv[fact[N-i]]%9;
        if(t>=2)f=0;
        else if(t==1)f=f*3%9;
        ans=(ans+f*(S[i]-'0'))%9;
    }
    if(ans==0)ans=9;
    cout<<ans<<endl;
}

signed main(){
    
    fact[0]=1;
    cnt[0]=0;
    for(int i=1;i<SIZE;i++){
        int t=i;
        while(t%3==0){
            t/=3;
            cnt[i]++;
        }
        cnt[i]+=cnt[i-1];
        fact[i]=fact[i-1]*t%9;
    }
    for(int i=0;i<9;i++){
        if(i%3==0)continue;
        for(int j=0;j<9;j++)if(i*j%9==1)inv[i]=j;
    }

    int T;
    cin>>T;
    while(T--)solve();
    return 0;
}
0