Submission #990627

# Submission time Handle Problem Language Result Execution time Memory
990627 2024-05-30T18:17:18 Z LOLOLO Mobitel (COCI19_mobitel) C++17
130 / 130
2524 ms 15308 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (ll)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 310;
vector <int> val;
ll dp[2][N][2024], cnt[N][N], mod = 1e9 + 7;
int mat[N][N];

int find(int v) {
    int p = upper_bound(all(val), v) - val.begin() - 1;
    return p;
}

ll solve() {
    int r, s, n;
    cin >> r >> s >> n;

    n--;
    for (int i = 1; i <= n; i++) 
        val.pb(n / i);


    uniquev(val);
    cnt[1][0] = 1;

    for (int i = 1; i <= r; i++) {
        for (int j = 1; j <= s; j++) {
            cin >> mat[i][j];
            cnt[i][j] = (cnt[i][j - 1] + cnt[i - 1][j]) % mod;
        }
    }

    dp[0][1][sz(val) - 1] = 1;

    for (int i = 1; i <= r; i++) {
        int t = i % 2;
        mem(dp[t], 0);
        for (int j = 1; j <= s; j++) {
            for (int f = 0; f < sz(val); f++) {
                int pos = find(val[f] / mat[i][j]);

                if (pos < 0)
                    continue;

                dp[t][j][pos] = (dp[t][j][pos] + dp[t][j - 1][f] + dp[1 - t][j][f]) % mod;
            }
        }
    }

    ll tot = 0;
    for (int i = 0; i < sz(val); i++)
        tot = (tot + dp[r % 2][s][i]) % mod;

    return (cnt[r][s] - tot + mod) % mod;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    int t = 1;
    //cin >> t;
 
    while (t--) {
        cout << solve() << '\n';
    }
 
    return 0;
} 
# Verdict Execution time Memory Grader output
1 Correct 47 ms 11356 KB Output is correct
2 Correct 48 ms 11352 KB Output is correct
3 Correct 328 ms 14796 KB Output is correct
4 Correct 367 ms 15296 KB Output is correct
5 Correct 327 ms 15300 KB Output is correct
6 Correct 358 ms 15308 KB Output is correct
7 Correct 160 ms 15052 KB Output is correct
8 Correct 1480 ms 15300 KB Output is correct
9 Correct 2475 ms 15296 KB Output is correct
10 Correct 2524 ms 15292 KB Output is correct