Submission #10251171
Source Code Expand
#include <bits/stdc++.h> using namespace std; template <class T, class F = multiplies<T>> T power(T a, long long n, F op = multiplies<T>(), T e = {1}) { assert(n >= 0); while (n) { if (n & 1) e = op(e, a); if (n >>= 1) a = op(a, a); } return e; } template <unsigned M> struct modular { using m = modular; unsigned v; modular(long long a = 0) : v((a %= M) < 0 ? a + M : a) {} m operator-() const { return m() -= *this; } m& operator+=(m r) { if ((v += r.v) >= M) v -= M; return *this; } m& operator-=(m r) { if (v < r.v) v += M; v -= r.v; return *this; } m& operator*=(m r) { v = (uint64_t)v * r.v % M; return *this; } m& operator/=(m r) { return *this *= power(r, M - 2); } friend m operator+(m l, m r) { return l += r; } friend m operator-(m l, m r) { return l -= r; } friend m operator*(m l, m r) { return l *= r; } friend m operator/(m l, m r) { return l /= r; } friend bool operator==(m l, m r) { return l.v == r.v; } friend string to_string(m a) { return to_string(a.v); } }; constexpr long long mod = 1e9 + 7; using mint = modular<mod>; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n >> m; int mx = 0; vector<mint> dp(mx + 1, 0), way(mx + 1, 1); for (int i = n; i; --i) { mx += 1 + mx / i; vector<mint> ndp(mx + 1), nway(mx + 1); for (int j = 0; j < (int)dp.size(); ++j) { for (int x = 0; x <= m; ++x) { if (x <= i) { int nj = j + (x + j) / i; ndp[nj] += (x + j) / i * way[j] + dp[j]; nway[nj] += way[j]; } else { ndp[j] += dp[j]; nway[j] += way[j]; } } } swap(dp, ndp); swap(way, nway); } mint res = power(mint(m + 1), n) * n * m / 2 - accumulate(begin(dp), end(dp), mint(0)); cout << res.v << '\n'; }
Submission Info
Submission Time | |
---|---|
Task | G - Mancala |
User | risujiroh |
Language | C++14 (GCC 5.4.1) |
Score | 1000 |
Code Size | 1880 Byte |
Status | AC |
Exec Time | 12 ms |
Memory | 256 KB |
Judge Result
Set Name | sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1000 / 1000 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt |
All | sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, sample-01.txt, sample-02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 1 ms | 256 KB |
01-02.txt | AC | 1 ms | 256 KB |
01-03.txt | AC | 1 ms | 256 KB |
01-04.txt | AC | 5 ms | 256 KB |
01-05.txt | AC | 1 ms | 256 KB |
01-06.txt | AC | 2 ms | 256 KB |
01-07.txt | AC | 4 ms | 256 KB |
01-08.txt | AC | 9 ms | 256 KB |
01-09.txt | AC | 11 ms | 256 KB |
01-10.txt | AC | 11 ms | 256 KB |
01-11.txt | AC | 12 ms | 256 KB |
01-12.txt | AC | 1 ms | 256 KB |
01-13.txt | AC | 4 ms | 256 KB |
01-14.txt | AC | 1 ms | 256 KB |
01-15.txt | AC | 5 ms | 256 KB |
01-16.txt | AC | 5 ms | 256 KB |
01-17.txt | AC | 1 ms | 256 KB |
01-18.txt | AC | 4 ms | 256 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |