結果

問題 No.435 占い(Extra)
ユーザー kimiyukikimiyuki
提出日時 2016-10-15 00:37:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,934 bytes
コンパイル時間 711 ms
コンパイル使用メモリ 78,300 KB
実行使用メモリ 81,408 KB
最終ジャッジ日時 2024-04-17 02:38:33
合計ジャッジ時間 5,242 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 5 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 4 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 25 ms
11,008 KB
testcase_13 AC 16 ms
5,376 KB
testcase_14 AC 15 ms
5,376 KB
testcase_15 AC 19 ms
5,376 KB
testcase_16 AC 45 ms
5,376 KB
testcase_17 AC 300 ms
5,376 KB
testcase_18 AC 25 ms
11,008 KB
testcase_19 AC 17 ms
5,376 KB
testcase_20 MLE -
testcase_21 AC 146 ms
11,008 KB
testcase_22 AC 134 ms
5,376 KB
testcase_23 AC 136 ms
5,376 KB
testcase_24 AC 164 ms
5,376 KB
testcase_25 AC 422 ms
5,376 KB
testcase_26 MLE -
testcase_27 AC 145 ms
11,136 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 150 ms
11,136 KB
testcase_30 MLE -
testcase_31 AC 162 ms
40,448 KB
testcase_32 AC 139 ms
17,928 KB
testcase_33 AC 142 ms
5,376 KB
testcase_34 AC 248 ms
5,376 KB
testcase_35 AC 140 ms
7,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
using namespace std;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }
template <typename T, typename X> auto vectors(T a, X x) { return vector<T>(x, a); }
template <typename T, typename X, typename Y, typename... Zs> auto vectors(T a, X x, Y y, Zs... zs) { auto cont = vectors(a, y, zs...); return vector<decltype(cont)>(x, cont); }
pair<int,int> zero(int k) {
    int z = 0;
    while (k % 3 == 0) { k /= 3; z += 1; }
    return { k, z };
}
const int inv[9] = { 0, 1, 5, 0, 7, 2, 0, 4, 8 };
int choose(int n, int r) {
    static vector<pair<int,int> > fact(1, make_pair(1, 0));
    if (fact.size() <= n) {
        int l = fact.size();
        fact.resize( n + 1);
        repeat_from (i,l,n+1) {
            int pk, pz; tie(pk, pz) = fact[i-1];
            int k, z; tie(k, z) = zero(i);
            fact[i] = { pk * k % 9, pz + z };
        }
    }
    r = min(r, n - r);
    int pk, pz; tie(pk, pz) = fact[n];
    int qk, qz; tie(qk, qz) = fact[r];
    int rk, rz; tie(rk, rz) = fact[n-r];
    int p = pk * inv[qk] * inv[rk] % 9;
    int z = pz - qz - rz;
    assert (z >= 0);
    return z == 0 ? p : z == 1 ? p * 3 % 9 : 0;
}
int main() {
    int t; cin >> t;
    while (t --) {
        int n, x, a, b, m; cin >> n >> x >> a >> b >> m;
        bool zero = true;
        int acc = x % 10;
        if (x % 10 != 0) zero = false;
        repeat_from (i,1,n) {
            x = ((x ^ a) + b) % m;
            acc = (acc + x % 10 * choose(n-1, i)) % 9;
            if (x % 10 != 0) zero = false;
        }
        if (not zero and acc == 0) acc = 9;
        cout << acc << endl;
    }
    return 0;
}
0