# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100675 | pzdba | Mobitel (COCI19_mobitel) | C++14 | 2302 ms | 5752 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>
using namespace std;
int mod = 1000000007;
int a[305][305];
int dp[2][2][305][1005];
int add(int a, int b){
return (a+b)%mod;
}
int main(){
int r, c, n;
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]);
if(n <= 1000){
int pv = 0, nt = 1;
for(int i=2;i<=r+c;i++){
memset(dp[nt][0], 0, sizeof(dp[nt][0]));
memset(dp[nt][1], 0, sizeof(dp[nt][1]));
for(int y=1;i-y>=1&&y<=r;y++){
int x = i-y;
if(i == 2){
if(a[y][x] >= n) dp[nt][0][y][n] = add(dp[nt][0][y][n], 1);
else dp[nt][0][y][a[y][x]] = add(dp[nt][0][y][a[y][x]], 1);
}
else{
for(int j=1;j<=n;j++){
int k = j*a[y][x];
if(k >= n){
dp[nt][0][y][n] = add(dp[nt][0][y][n], dp[pv][0][y][j]);
if(y-1 >= 1) dp[nt][0][y][n] = add(dp[nt][0][y][n], dp[pv][0][y-1][j]);
}
else{
dp[nt][0][y][k] = add(dp[nt][0][y][k], dp[pv][0][y][j]);
if(y-1 >= 1) dp[nt][0][y][k] = add(dp[nt][0][y][k], dp[pv][0][y-1][j]);
}
}
}
}
swap(pv, nt);
}
printf("%d\n", dp[pv][0][r][n]);
}
else{
int pv = 0, nt = 1;
for(int i=2;i<=r+c;i++){
memset(dp[nt][0], 0, sizeof(dp[nt][0]));
memset(dp[nt][1], 0, sizeof(dp[nt][1]));
for(int y=1;i-y>=1&&y<=r;y++){
int x = i-y;
if(y > r || x > c) continue;
if(i == 2){
if(a[y][x] >= n) dp[nt][0][y][n] = add(dp[nt][0][y][n], 1);
else dp[nt][0][y][a[y][x]] = add(dp[nt][0][y][a[y][x]], 1);
}
else{
for(int j=1;j<=1000;j++){
int k = j*a[y][x];
if(k > 1000){
k = (n+k-1)/k;
dp[nt][1][y][k] = add(dp[nt][1][y][k], dp[pv][0][y][j]);
if(y-1 >= 1) dp[nt][1][y][k] = add(dp[nt][1][y][k], dp[pv][1][y-1][j]);
}
else{
dp[nt][0][y][k] = add(dp[nt][0][y][k], dp[pv][0][y][j]);
if(y-1 >= 1) dp[nt][0][y][k] = add(dp[nt][0][y][k], dp[pv][0][y-1][j]);
}
}
for(int j=1;j<=1000;j++){
int k = (j+a[y][x]-1)/a[y][x];
dp[nt][1][y][k] = add(dp[nt][1][y][k], dp[pv][1][y][j]);
if(y-1 >= 1) dp[nt][1][y][k] = add(dp[nt][1][y][k], dp[pv][1][y-1][j]);
}
}
}
swap(pv, nt);
}
printf("%d\n", dp[pv][1][r][1]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |