結果

問題 No.434 占い
ユーザー kimiyukikimiyuki
提出日時 2016-10-15 00:14:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,661 bytes
コンパイル時間 1,026 ms
コンパイル使用メモリ 77,196 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-02 00:03:13
合計ジャッジ時間 2,134 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 16 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 6 ms
6,944 KB
testcase_16 AC 5 ms
6,940 KB
testcase_17 AC 5 ms
6,940 KB
testcase_18 AC 5 ms
6,940 KB
testcase_19 WA -
testcase_20 AC 130 ms
6,940 KB
testcase_21 AC 5 ms
6,944 KB
testcase_22 AC 5 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 4 ms
6,944 KB
testcase_25 AC 6 ms
6,944 KB
testcase_26 AC 4 ms
6,940 KB
testcase_27 AC 6 ms
6,944 KB
testcase_28 AC 6 ms
6,948 KB
testcase_29 WA -
testcase_30 AC 116 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#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))
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) {
    const int mod = 9;
    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 --) {
        string s; cin >> s;
        int n = s.length();
        int acc = 0;
        repeat (j,n) acc += (s[j] - '0') * choose(n-1, j);
        while (acc >= 10) acc = acc / 10 + acc % 10;
        cout << acc << endl;
    }
    return 0;
}
0