Submission #225144

# Submission time Handle Problem Language Result Execution time Memory
225144 2020-04-19T10:12:55 Z Vimmer Mobitel (COCI19_mobitel) C++14
0 / 130
29 ms 3072 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 100005
#define MOD ll(1e9 + 7)

using namespace std;

typedef long long ll;

typedef long double ld;



ll a[305][305], dp[305][305], f[305][305], n, m, s, ans;

int mk[305][305];

vector <pair <ll, ll> >  vr;

void rec(int x, int y, ll sm, ll kol);

void dfs(int x, int y)
{
    if (mk[x][y] == sz(vr)) return;

    mk[x][y] = sz(vr);

    if (x + 1 != n)
    {
        if (a[x + 1][y] == 1) dfs(x + 1, y);
          else rec(x + 1, y, vr.back().F * a[x + 1][y], (vr.back().S * f[x][y]) % MOD);
    }

    if (y + 1 != m)
    {
        if (a[x][y + 1] == 1) dfs(x, y + 1);
          else rec(x, y + 1, vr.back().F * a[x][y + 1], (vr.back().S * f[x][y]) % MOD);
    }
}

void calc(int x, int y)
{
    f[x][y] = 1;

    set <int> now, nxt; nxt.clear(); now.clear();

    now.insert(y);

    int i = x;

    while (1)
    {
        if (sz(now) == 0) break;

        for (auto it : now)
        {
            if (i != x || it != y) f[i][it] = 0;

            if (i != x && i != 0 && a[i - 1][it] == 1) f[i][it] = (f[i][it] + f[i - 1][it]) % MOD;

            if (it != 0 && it != y && a[i][it - 1] == 1) f[i][it] = (f[i][it] + f[i][it - 1]) % MOD;

            if (it + 1 != m && a[i][it + 1] == 1) now.insert(it + 1);

            if (i + 1 != n && a[i + 1][it] == 1) nxt.insert(it);
        }

        now = nxt;

        nxt.clear();

        i++;
    }

    dfs(x, y);
}

void rec(int x, int y, ll sm, ll kol)
{
    if (sm >= s) {ans = (ans + (kol * dp[x][y]) % MOD) % MOD; return;}

    if (a[x][y] == 1) {vr.pb({sm, kol}); calc(x, y); return;}

    if (x + 1 != n) rec(x + 1, y, sm * a[x + 1][y], kol);

    if (y + 1 != m) rec(x, y + 1, sm * a[x][y + 1], kol);
}


int main()
{

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

    cin >> n >> m >> s;

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

    dp[n - 1][m - 1] = 1;

    for (int i = n - 1; i >= 0; i--)
        for (int j = m - 1; j >= 0; j--)
        {
            if (i + 1 != n) dp[i][j] = (dp[i][j] + dp[i + 1][j]) % MOD;

            if (j + 1 != m) dp[i][j] = (dp[i][j] + dp[i][j + 1]) % MOD;
        }

//    for (int i = 0; i < n; i++)
//        for (int j = 0; j < m; j++)
//        {
//            if (a[i][j] != 1) continue;
//
//            bool fr = 0;
//
//            if (i != 0 && a[i - 1][j] == 1) {fr = 1; f[i][j] = (f[i - 1][j] + f[i][j]) % MOD;}
//
//            if (j != 0 && a[i][j - 1] == 1) {fr = 1; f[i][j] = (f[i][j - 1] + f[i][j]) % MOD;}
//
//            if (!fr) f[i][j] = 1;
//        }


    rec(0, 0, a[0][0], 1);

    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 2816 KB Output isn't correct
2 Incorrect 21 ms 3072 KB Output isn't correct
3 Incorrect 7 ms 1280 KB Output isn't correct
4 Incorrect 7 ms 1152 KB Output isn't correct
5 Incorrect 9 ms 1152 KB Output isn't correct
6 Incorrect 7 ms 1152 KB Output isn't correct
7 Incorrect 6 ms 1024 KB Output isn't correct
8 Incorrect 14 ms 2304 KB Output isn't correct
9 Incorrect 29 ms 2936 KB Output isn't correct
10 Incorrect 22 ms 2944 KB Output isn't correct