Submission #225225

# Submission time Handle Problem Language Result Execution time Memory
225225 2020-04-19T16:03:03 Z Vimmer Mobitel (COCI19_mobitel) C++14
130 / 130
3234 ms 9848 KB
#include <bits/stdc++.h>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 200005
#define MOD ll(1e9 + 7)

using namespace std;

typedef long long ll;


int dp[2][301][2005], opr[1000005];

ll a[301][301];

vector <ll> vr;

int main()
{

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n, m, k;

    cin >> n >> m >> k;

    vr.pb(k);

    for (int i = 2; i <= k; i++)
    {
        ll val = vr.back();

        bool f = 1;

        while ((val - 1) * i >= k) {if (!f) opr[val] = sz(vr); val--; f = 0;}

        if (!f) opr[val] = sz(vr);

        if (vr.back() != val) vr.pb(val);
    }

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) cin >> a[i][j];

   dp[0][0][opr[min(k, a[0][0])]] = 1;

    for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
              for (int u = 0; u < sz(vr); u++)
                {
                    if (dp[0][j][u] == 0) continue;

                    ll val = vr[u];

                    if (i + 1 != n) dp[1][j][opr[min(k, val * a[i + 1][j])]] = (dp[1][j][opr[min(k, val * a[i + 1][j])]] + dp[0][j][u]) % MOD;

                    if (j + 1 != m) dp[0][j + 1][opr[min(k, val * a[i][j + 1])]] = (dp[0][j + 1][opr[min(k, val * a[i][j + 1])]] + dp[0][j][u]) % MOD;
                }

            if (i + 1 != n)
            {
                for (int j = 0; j < m; j++)
                  for (int u = 0; u < sz(vr); u++) {dp[0][j][u] = dp[1][j][u]; dp[1][j][u] = 0;}
            }
        }

    cout << dp[0][m - 1][0];
}
# Verdict Execution time Memory Grader output
1 Correct 48 ms 3456 KB Output is correct
2 Correct 50 ms 3584 KB Output is correct
3 Correct 120 ms 5632 KB Output is correct
4 Correct 126 ms 6144 KB Output is correct
5 Correct 272 ms 6156 KB Output is correct
6 Correct 248 ms 6144 KB Output is correct
7 Correct 115 ms 5248 KB Output is correct
8 Correct 1627 ms 8288 KB Output is correct
9 Correct 3150 ms 9720 KB Output is correct
10 Correct 3234 ms 9848 KB Output is correct