QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#640769#7996. 报数 IVucup-team3519#WA 116ms3708kbC++173.5kb2024-10-14 15:54:182024-10-14 15:54:19

Judging History

你现在查看的是最新测评结果

  • [2024-10-14 15:54:19]
  • 评测
  • 测评结果:WA
  • 用时:116ms
  • 内存:3708kb
  • [2024-10-14 15:54:18]
  • 提交

answer

#include <bits/stdc++.h>

template <int m>
class ModInt {
    int raw;
    using mint = ModInt;
    using i64 = int64_t;

public:
    ModInt() : raw(0) {}
    ModInt(const auto &v) {
        raw = v % m;
        if (raw < 0) {
            raw += m;
        }
    }
    int operator()() const {
        return raw;
    }

    mint &operator+=(const mint &rhs) {
        raw += rhs.raw;
        if (raw >= m) {
            raw -= m;
        }
        return *this;
    }
    mint &operator-=(const mint &rhs) {
        raw -= rhs.raw;
        if (raw < 0) {
            raw += m;
        }
        return *this;
    }
    mint &operator*=(const mint &rhs) {
        raw = (i64)raw * rhs.raw % m;
        return *this;
    }
    mint &operator/=(const mint &rhs) {
        return *this *= qpow(rhs, m - 2);
    }

    friend mint operator+(const mint &lhs, const mint &rhs) {
        return mint{lhs} += rhs;
    }
    friend mint operator-(const mint &lhs, const mint &rhs) {
        return mint{lhs} -= rhs;
    }
    friend mint operator*(const mint &lhs, const mint &rhs) {
        return mint{lhs} *= rhs;
    }
    friend mint operator/(const mint &lhs, const mint &rhs) {
        return mint{lhs} /= rhs;
    }

    static mint qpow(mint a, i64 b) {
        mint res = 1;
        while (b) {
            if (b & 1) {
                res *= a;
            }
            a *= a, b >>= 1;
        }
        return res;
    }
};

using mint = ModInt<static_cast<int>(1e9 + 7)>;

int mod(std::string s) {
    int res = 0;
    for (char c : s) {
        res += (c - '0');
    }
    return res % 9;
}
mint val(std::string s) {
    mint res = 0;
    for (char c : s) {
        res = res * 10 + (c - '0');
    }
    return res;
}

void solve() {
    std::string s;
    std::cin >> s;

    int k, m;
    std::cin >> k >> m;

    if (k >= 10) {
        if (m > 9) {
            std::cout << "0\n";
        } else {
            m %= 9;
            mint ans = val(s), p = mod(s);
            std::cout << ((ans - p + 9 - m) / 9)() << '\n';
        }
        return;
    }

    int sum = 0;
    std::vector<mint> g;
    for (char c : s) {
        int d = c - '0';
        
        std::vector<mint> ng(std::max<int>(sum + d, g.size() + 10));
        for (int i = 0; i < d; ++i) {
            ng[sum + i] += 1;
        }
        for (int i = 0; i < 10; ++i) {
            for (int x = 0; x < g.size(); ++x) {
                ng[x + i] += g[x];
            }
        }
        sum += d;

        g.swap(ng);
        while (!g.empty() && g.back()() == 0) {
            g.pop_back();
        }
    }

    if (g.size() < sum + 1) {
        g.resize(sum + 1);
    }
    g[sum] += 1;
    g[0] -= 1;

    auto f = [](int x) {
        int res = 0;
        while (x) {
            res += x % 10;
            x /= 10;
        }
        return res;
    };
    for (int i = 1; i <= k - 1; ++i) {
        std::vector<mint> ng(g.size());

        for (int x = 0; x < g.size(); ++x) {
            ng[f(x)] += g[x];
        }

        g.swap(ng);
        while (!g.empty() && g.back()() == 0) {
            g.pop_back();
        }
    }

    if (g.size() < m + 1) {
        std::cout << "0\n";
    } else {
        std::cout << g[m]() << '\n';
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;
    std::cin >> t;

    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3708kb

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3464kb

input:

5
114 1 5
514 2 10
114514 3 7
1919810 2 13
1145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810 1 79

output:

8
10
12724
504
481046284

result:

ok 5 lines

Test #3:

score: -100
Wrong Answer
time: 116ms
memory: 3688kb

input:

5
3134666912140933323880320519044791121794814671711104987304374190280064994554822259889216567113228716903875026053927191961850586115167336109747673868148288830282192461669674173201533887392623483710043038941036243583011049049915834937139438028987629569618561762595613799223807979488245056374812076511...

output:

0
613343513
0
500149787
821256555

result:

wrong answer 5th lines differ - expected: '932367667', found: '821256555'