結果

問題 No.435 占い(Extra)
ユーザー pekempeypekempey
提出日時 2016-11-22 19:45:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,416 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 175,448 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 02:52:54
合計ジャッジ時間 4,685 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 14 ms
5,376 KB
testcase_13 AC 13 ms
5,376 KB
testcase_14 AC 13 ms
5,376 KB
testcase_15 AC 12 ms
5,376 KB
testcase_16 AC 13 ms
5,376 KB
testcase_17 WA -
testcase_18 AC 12 ms
5,376 KB
testcase_19 AC 12 ms
5,376 KB
testcase_20 AC 108 ms
5,376 KB
testcase_21 AC 111 ms
5,376 KB
testcase_22 AC 110 ms
5,376 KB
testcase_23 AC 110 ms
5,376 KB
testcase_24 AC 110 ms
5,376 KB
testcase_25 AC 115 ms
5,376 KB
testcase_26 AC 112 ms
5,376 KB
testcase_27 AC 110 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 109 ms
5,376 KB
testcase_30 AC 110 ms
5,376 KB
testcase_31 AC 96 ms
5,376 KB
testcase_32 AC 101 ms
5,376 KB
testcase_33 AC 112 ms
5,376 KB
testcase_34 AC 117 ms
5,376 KB
testcase_35 AC 112 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#ifndef LOCAL
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

int in() {
    int n, c;
    while ((c = getchar()) < '0') if (c == EOF) abort();
    n = c - '0';
    while ((c = getchar()) >= '0') n = n * 10 + c - '0';
    return n;
}

void out(int n) {
    int res[11], i = 0;
    do { res[i++] = n % 10, n /= 10; } while (n);
    while (i) putchar(res[--i] + '0');
    putchar('\n');
}

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

pair<int, int> decomp(int n) {
    if (n == 0) return{ 0, 0 };
    int three = 0;
    for (; n % 3 == 0; n /= 3) three++;
    return{ n, three };
}

int main() {
    int T = in();
    while (T--) {
        int n = in() - 1, x = in(), a = in(), b = in(), m = in();
        bool z = true;
        int nPi = 1, iPi = 1, num3 = 0, den3 = 0;
        int64_t ans = 0;
        for (int i = 0; i <= n; i++, x = ((x ^ a) + b) % m) {
            int d = x % 10;
            if (d != 0) z = false;
            int cnt3 = num3 - den3;
            ans += nPi * inv[iPi] * (cnt3 == 0 ? 1 : cnt3 == 1 ? 3 : 0) * d;
            if (i < n) {
                for (nPi *= n - i; nPi % 3 == 0; nPi /= 3) num3++;
                for (iPi *= i + 1; iPi % 3 == 0; iPi /= 3) den3++;
                nPi %= 9;
                iPi %= 9;
            }
        }
        out(z ? 0 : (ans - 1) % 9 + 1);
    }
}
0