結果

問題 No.435 占い(Extra)
ユーザー pekempeypekempey
提出日時 2016-11-22 19:11:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,899 bytes
コンパイル時間 2,240 ms
コンパイル使用メモリ 178,576 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 02:51:39
合計ジャッジ時間 5,079 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 2 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 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 11 ms
5,376 KB
testcase_13 AC 11 ms
5,376 KB
testcase_14 AC 12 ms
5,376 KB
testcase_15 AC 13 ms
5,376 KB
testcase_16 AC 13 ms
5,376 KB
testcase_17 AC 22 ms
5,376 KB
testcase_18 AC 13 ms
5,376 KB
testcase_19 AC 12 ms
5,376 KB
testcase_20 AC 106 ms
5,376 KB
testcase_21 AC 109 ms
5,376 KB
testcase_22 AC 112 ms
5,376 KB
testcase_23 AC 107 ms
5,376 KB
testcase_24 AC 106 ms
5,376 KB
testcase_25 AC 114 ms
5,376 KB
testcase_26 AC 104 ms
5,376 KB
testcase_27 AC 109 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 106 ms
5,376 KB
testcase_30 AC 114 ms
5,376 KB
testcase_31 AC 88 ms
5,376 KB
testcase_32 AC 92 ms
5,376 KB
testcase_33 AC 107 ms
5,376 KB
testcase_34 AC 116 ms
5,376 KB
testcase_35 AC 106 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#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');
}

char p2[256], inv[9];

pair<char, int> decomp(int n) {
    if (n == 0) return{ 0, 0 };
    int three = 0;
    while (n % 3 == 0) {
        n /= 3;
        three++;
    }
    return{ inv[n % 9], three };
}

void upd(char &x, char y) {
    if ((x += y) >= 6) x -= 6;
}

int main() {
    p2[0] = 1;
    for (int i = 1; i < 256; i++) p2[i] = p2[i - 1] * 2 % 9;
    for (int i = 0; i < 6; i++) inv[p2[i]] = i;

    int T = in();
    while (T--) {
        int n = in() - 1, x = in(), a = in(), b = in(), m = in();
        auto N = decomp(n);
        pair<char, int> L(0, 0);
        pair<char, int> R = N;
        bool zero = true;
        uint32_t ans = 0;
        for (int i = 0; i <= n; i++) {
            if (zero && x % 10 != 0) zero = false;
            char two = N.first + (6 - L.first) + (6 - R.first);
            int three = N.second - L.second - R.second;
            if (three <= 1) {
                int c = p2[two] * (three == 0 ? 1 : three == 1 ? 3 : 0);
                ans += c * (x % 10);
            }
            auto ll = decomp(i + 1);
            auto rr = decomp(n - i);
            upd(L.first, ll.first);
            L.second += ll.second;
            upd(R.first, 6 - rr.first);
            R.second -= rr.second;
            x = ((x ^ a) + b) % m;
        }
        ans %= 9;
        if (ans == 0) ans = 9;
        if (zero) ans = 0;
        out(ans);
    }
}
0