結果

問題 No.435 占い(Extra)
ユーザー maspymaspy
提出日時 2020-04-24 00:36:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 481 ms / 2,000 ms
コード長 1,098 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 72,296 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 03:07:08
合計ジャッジ時間 5,521 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 20 ms
6,940 KB
testcase_13 AC 20 ms
6,940 KB
testcase_14 AC 20 ms
6,944 KB
testcase_15 AC 22 ms
6,940 KB
testcase_16 AC 49 ms
6,940 KB
testcase_17 AC 297 ms
6,940 KB
testcase_18 AC 20 ms
6,940 KB
testcase_19 AC 20 ms
6,944 KB
testcase_20 AC 183 ms
6,940 KB
testcase_21 AC 181 ms
6,944 KB
testcase_22 AC 178 ms
6,940 KB
testcase_23 AC 182 ms
6,940 KB
testcase_24 AC 210 ms
6,940 KB
testcase_25 AC 481 ms
6,944 KB
testcase_26 AC 182 ms
6,944 KB
testcase_27 AC 181 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 203 ms
6,940 KB
testcase_30 AC 182 ms
6,944 KB
testcase_31 AC 148 ms
6,940 KB
testcase_32 AC 162 ms
6,940 KB
testcase_33 AC 194 ms
6,940 KB
testcase_34 AC 310 ms
6,940 KB
testcase_35 AC 193 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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 % 9];
        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