답안 #1100442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100442 2024-10-14T00:31:16 Z vjudge1 Mobitel (COCI19_mobitel) C++17
130 / 130
2951 ms 19640 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define REPD(i, a) for (int i = (a) - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
#define MAX                     303
int numRow, numCol, Lim;
int A[MAX][MAX];

int dp[2][MAX][2005];
int cnt[MAX][MAX];
vector<int> comp;

int find(int x){
    return upper_bound(comp.begin(), comp.end(), x) - comp.begin() - 1;
}

void process(void){
    cin >> numRow >> numCol >> Lim;
    FOR(i, 1, numRow) FOR(j, 1, numCol){
        cin >> A[i][j];
    }

    --Lim;
    for (int i = 1; i <= Lim; ++i){
        comp.emplace_back(Lim / i);
    }

    sort(comp.begin(), comp.end());
    comp.resize(unique(comp.begin(), comp.end()) - comp.begin());

    cnt[1][1] = 1;
    for (int i = 1; i <= numRow; ++i){
        for (int j = 1; j <= numCol; ++j) if(i != 1 || j != 1){
            cnt[i][j] = (cnt[i][j - 1] + cnt[i - 1][j]) % Mod;
        }
    }
    dp[0][1][(int)comp.size() - 1] = 1;

    FOR(i, 1, numRow) {
        memset(dp[1], 0, sizeof dp[1]);
        FOR(j, 1, numCol) REP(f, (int)comp.size()){
            int nxt = find(comp[f] / A[i][j]);
            if(nxt < 0) continue;
            dp[1][j][nxt] = (dp[1][j][nxt] + dp[0][j][f] + dp[1][j - 1][f]) % Mod;
        }
        swap(dp[1], dp[0]);
    }
    int ans = 0;
    for (int i = 0; i < (int)comp.size(); ++i){
        ans += dp[0][numCol][i];
        ans %= Mod;
    }
    cout << (cnt[numRow][numCol] - ans + Mod) % Mod;
}
signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    process();
    return (0 ^ 0);
}




# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 11232 KB Output is correct
2 Correct 177 ms 11344 KB Output is correct
3 Correct 415 ms 18608 KB Output is correct
4 Correct 431 ms 18624 KB Output is correct
5 Correct 392 ms 18628 KB Output is correct
6 Correct 409 ms 18640 KB Output is correct
7 Correct 215 ms 19144 KB Output is correct
8 Correct 1788 ms 19392 KB Output is correct
9 Correct 2936 ms 19640 KB Output is correct
10 Correct 2951 ms 19640 KB Output is correct