結果

問題 No.435 占い(Extra)
ユーザー tottoripapertottoripaper
提出日時 2016-10-19 18:14:45
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,012 bytes
コンパイル時間 1,323 ms
コンパイル使用メモリ 159,488 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 02:47:34
合計ジャッジ時間 6,475 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 RE -
testcase_13 AC 24 ms
5,376 KB
testcase_14 AC 24 ms
5,376 KB
testcase_15 AC 25 ms
5,376 KB
testcase_16 AC 33 ms
5,376 KB
testcase_17 AC 82 ms
5,376 KB
testcase_18 RE -
testcase_19 AC 25 ms
5,376 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 217 ms
5,376 KB
testcase_23 AC 220 ms
5,376 KB
testcase_24 AC 224 ms
5,376 KB
testcase_25 AC 288 ms
5,376 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 3 ms
5,376 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 239 ms
5,376 KB
testcase_34 AC 277 ms
5,376 KB
testcase_35 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |     scanf("%d", &T);
      |     ~~~~~^~~~~~~~~~
main.cpp:49:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   49 |         scanf("%d %d %d %d %d", &N, &X, &A, &B, &M);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int S[100100];
int inv[100100];

template <typename T>
T expt(T a, T n, T mod = std::numeric_limits<T>::max()){
    T res = 1;
    while(n){
        if(n & 1){res = res * a % mod;}
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    //*
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    /*/
      /*/

    for(int i=1;i<=100000;++i){
        // generate inv
        if(i == 1 || i % 3 == 0){inv[i] = 1;}
        else{
            inv[i] = expt(i % 9, 5, 9);
        }
    }
    
    
    int T;
    scanf("%d", &T);

    for(int _=0;_<T;++_){
        int N, X, A, B, M;
        scanf("%d %d %d %d %d", &N, &X, &A, &B, &M);
        
        S[0] = X;
        for(int i=1;i<N;++i){
            S[i] = ((S[i-1] ^ A) + B) % M;
        }

        for(int i=0;i<N;++i){
            S[i] %= 10;
        }

        int l = N, n = l - 1;

        if(count(S, S+l, 0) == l){
            puts("0");
            continue;
        }
        
        int three_n = 0, m = 1;

        int res = 0;
        for(int i=0;i<=n;++i){
            if(i >= 1){
                int x = i;
                while(x % 3 == 0){
                    --three_n;
                    x /= 3;
                }

                m = m * inv[x] % 9;
                
                x = n - i + 1;

                while(x % 3 == 0){
                    ++three_n;
                    x /= 3;
                }

                m = m * x % 9;
            }
            
            int a = S[i], three_n2 = three_n + (a % 3 == 0) + (a % 9 == 0);
            if(three_n2 < 2){
                res = (res + a * m % 9 * expt(3, three_n) % 9) % 9;
            }
        }

        printf("%d\n", res > 0 ? res : 9);
    }
}
0