# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
314079 | phathnv | Mobitel (COCI19_mobitel) | C++11 | 1581 ms | 5504 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define taskname "MOBITEL"
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int R = 301;
const int sqrtN = 1001;
const int MOD = 1e9 + 7;
int r, c, n, a[R][R];
int s, dp[2][R][2][sqrtN];
void readInput(){
scanf("%d %d %d", &r, &c, &n);
for(int i = 1; i <= r; i++)
for(int j = 1; j <= c; j++)
scanf("%d", &a[i][j]);
}
void add(int &x, const int &y){
x += y;
x -= (x >= MOD) * MOD;
}
void nextState(int &k, int &p, int factor){
if (k == 1){
p = (p + factor - 1) / factor;
} else {
int tmp = p * factor;
if (tmp >= s){
k = 1;
p = (n + tmp - 1) / tmp;
} else {
p = tmp;
}
}
}
void solve(){
s = ceil(sqrt(n));
dp[0][1][0][1] = 1;
for(int i = 0; i < r; i++){
int id = i & 1;
for(int j = 1; j <= c; j++)
for(int k = 0; k < 2; k++)
for(int p = 1; p <= s; p++)
dp[id ^ 1][j][k][p] = 0;
for(int j = 1; j <= c; j++)
for(int p = 1; p <= s; p++){
int tmp = p * a[i + 1][j];
if (tmp < s)
add(dp[id ^ 1][j][0][tmp], dp[id][j][0][p]);
else
add(dp[id ^ 1][j][1][(n + tmp - 1) / tmp], dp[id][j][0][p]);
add(dp[id ^ 1][j][1][(p + a[i + 1][j] - 1) / a[i + 1][j]], dp[id][j][1][p]);
}
for(int j = 1; j < c; j++)
for(int p = 1; p <= s; p++){
int tmp = p * a[i + 1][j + 1];
if (tmp < s)
add(dp[id ^ 1][j + 1][0][tmp], dp[id ^ 1][j][0][p]);
else
add(dp[id ^ 1][j + 1][1][(n + tmp - 1) / tmp], dp[id ^ 1][j][0][p]);
add(dp[id ^ 1][j + 1][1][(p + a[i + 1][j + 1] - 1) / a[i + 1][j + 1]], dp[id ^ 1][j][1][p]);
}
}
printf("%d", dp[r & 1][c][1][1]);
}
int main(){
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
readInput();
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |