結果

問題 No.435 占い(Extra)
ユーザー maspymaspy
提出日時 2020-04-24 00:35:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,094 bytes
コンパイル時間 725 ms
コンパイル使用メモリ 71,168 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 03:06:56
合計ジャッジ時間 5,534 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 WA -
testcase_17 AC 342 ms
5,376 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 WA -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 2 ms
5,376 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
typedef long long ll;

int inv[9] = {0, 1, 5, 0, 7, 2, 0, 4, 8};

void solve()
{
    ll n, x, a, b, m, comb, ord;
    cin >> n >> x >> a >> b >> m;
    n--;
    comb = 1;
    ord = 0;
    int ret = 0;
    bool all_zero = true;
    for (int i = 0; i <= n; i++)
    {
        int s = x % 10;
        all_zero &= (s == 0);
        if (ord == 0)
        {
            ret += comb * s;
        }
        else if (ord == 1)
        {
            ret += comb * 3 * s;
        }
        if (i == n)
            break;
        int t = n - i;
        while (t % 3 == 0)
        {
            t /= 3;
            ord += 1;
        }
        comb *= t;
        comb %= 9;
        t = i + 1;
        while (t % 3 == 0)
        {
            t /= 3;
            ord -= 1;
        }
        comb *= inv[t];
        comb %= 9;
        x = ((x ^ a) + b) % m;
    }
    ret %= 9;
    if (ret == 0 && !all_zero)
    {
        ret = 9;
    }
    cout << ret << endl;
}

int main()
{
    int T;
    cin >> T;
    for (int i = 0; i < T; i++)
        solve();
    return 0;
}
0