Submission #795972

# Submission time Handle Problem Language Result Execution time Memory
795972 2023-07-28T02:23:47 Z Cookie Mobitel (COCI19_mobitel) C++14
130 / 130
1110 ms 5904 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 7;
const int mxn = 1e6 + 5, mxq = 2e5 + 5, sq = 400, mxv = 2e7 + 5;
//const int base = (1 << 18);
int r, s, n;
int a[505][505];
int dp[305][2005], id[mxn + 1], predp[305][2005];
int cc(int u, int v){
    return((u - 1) / v + 1);
}
void add(int &a, int b){
    a += b;
    if(a >= mod)a -= mod;
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> r >> s >> n;
    for(int i = 1; i <= r; i++){
        for(int j = 1; j <= s; j++){
            cin >> a[i][j];
        }
    }
    vt<int>care;
    for(int i = 1; i <= n;){
        int cand = cc(n, i);
        id[cand] = sz(care);
        care.pb(cand);
        if(i == n)break;
        i = cc(n, cc(n, i) - 1);
    }
    dp[1][id[cc(n, a[1][1])]] = 1;
    for(int i = 1; i <= r; i++){
        for(int j = 1; j <= s; j++){
            for(int k = 0; k < sz(care); k++){
                int nwid = id[cc(care[k], a[i][j])];
                
                if(i > 1){
                    add(dp[j][nwid], predp[j][k]); 
                }if(j > 1){
                    add(dp[j][nwid], dp[j - 1][k]);
                }
                
            }
            
        }
        for(int j = 1; j <= s; j++){
            for(int k = 0; k < sz(care);  k++){
                predp[j][k] = dp[j][k]; dp[j][k] = 0;
            }
        }
    }
   
    cout << predp[s][sz(care) - 1];
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 3284 KB Output is correct
2 Correct 23 ms 3436 KB Output is correct
3 Correct 126 ms 2356 KB Output is correct
4 Correct 136 ms 2388 KB Output is correct
5 Correct 126 ms 2388 KB Output is correct
6 Correct 126 ms 2388 KB Output is correct
7 Correct 58 ms 1748 KB Output is correct
8 Correct 599 ms 4472 KB Output is correct
9 Correct 1100 ms 5852 KB Output is correct
10 Correct 1110 ms 5904 KB Output is correct