Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <map>
- using namespace std;
- typedef long long ll;
- vector<ll> a;
- vector<vector<map<pair<ll, ll>, ll> > > dp;
- //#define _DEBUG
- //#define _FILE
- void print(ll it) {
- #ifdef _DEBUG
- for (ll i = 0; i < 10; i++) {
- cout << dp[it][i].size() << "->";
- for (auto k = dp[it][i].begin(); k != dp[it][i].end(); k++) {
- cout << k->first.first << ';' << k->first.second << ':' << k->second << '|';
- }
- cout << "|||";
- }
- cout << endl;
- #endif
- }
- using namespace std;
- int main() {
- #ifdef _FILE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- cin.tie(0);
- ios_base::sync_with_stdio(0);
- ll n;
- cin >> n;
- dp.resize(n);
- a.resize(n);
- for (ll i = 0; i < n; i++) {
- cin >> a[i];
- dp[i].resize(10);
- }
- dp[0][a[0] % 10][make_pair(0, a[0] % 10)] = 1;
- print(0);
- for (ll i = 1; i < n; i++) {
- for (ll j = 0; j < 10; j++) {
- for (auto k = dp[i - 1][j].begin(); k != dp[i - 1][j].end(); k++) {
- ll pr_sum = k->first.first;
- ll pr_mult = k->first.second;
- ll pr_count = k->second;
- //prod
- ll pos = (pr_mult * a[i] + pr_sum) % 10;
- ll x = (pr_mult * a[i]) % 10;
- dp[i][pos][make_pair(pr_sum, x)] += pr_count;
- dp[i][pos][make_pair(pr_sum, x)] %= (1000000007);
- //summ
- pos = (pr_mult + a[i] + pr_sum) % 10;
- x = (pr_mult + pr_sum) % 10;
- dp[i][pos][make_pair(x, a[i] % 10)] += pr_count;
- dp[i][pos][make_pair(x, a[i] % 10)] %= (1000000007);
- }
- }
- print(i);
- }
- for (ll i = 0; i < 10; i++) {
- ll res = 0;
- for (auto it = dp[n - 1][i].begin(); it != dp[n - 1][i].end(); it++) {
- res += it->second;
- }
- cout << res % (1000000007)<< ' ';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement