結果

問題 No.435 占い(Extra)
ユーザー latte0119latte0119
提出日時 2016-10-15 01:19:06
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,570 bytes
コンパイル時間 1,078 ms
コンパイル使用メモリ 161,276 KB
実行使用メモリ 237,952 KB
最終ジャッジ日時 2024-04-17 02:39:47
合計ジャッジ時間 10,744 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 MLE -
testcase_29 MLE -
testcase_30 MLE -
testcase_31 MLE -
testcase_32 MLE -
testcase_33 MLE -
testcase_34 MLE -
testcase_35 MLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |     scanf("%lld%lld%lld%lld%lld",&N,&x,&a,&b,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:68:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |     scanf("%lld",&T);
      |     ~~~~~^~~~~~~~~~~

ソースコード

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=10000000;
int fact[SIZE],cnt[SIZE];
int inv[9];
int A[SIZE];
void solve(){
    int N,x,a,b,m;
    scanf("%lld%lld%lld%lld%lld",&N,&x,&a,&b,&m);
    A[0]=x;
    for(int i=1;i<N;i++){
        A[i]=((A[i-1]^a)+b)%m;
    }
    for(int i=0;i<N;i++)A[i]%=10;

    if(count(A,A+N,0)==N){
        puts("0");
        return;
    }

    N--;
    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*A[i])%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;
    scanf("%lld",&T);
    while(T--)solve();
    return 0;
}
0