Submission #314077

# Submission time Handle Problem Language Result Execution time Memory
314077 2020-10-18T07:35:50 Z phathnv Mobitel (COCI19_mobitel) C++11
130 / 130
3520 ms 5636 KB
#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 {
        ll tmp = (ll) 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 = 0; p <= s; p++)
                    dp[id ^ 1][j][k][p] = 0;

        for(int j = 1; j <= c; j++)
            for(int k = 0; k < 2; k++)
                for(int p = 0; p <= s; p++){
                    if (!dp[id][j][k][p])
                        continue;
                    int nxtK = k;
                    int nxtP = p;
                    nextState(nxtK, nxtP, a[i + 1][j]);
                    add(dp[id ^ 1][j][nxtK][nxtP], dp[id][j][k][p]);
                }
        for(int j = 1; j < c; j++)
            for(int k = 0; k < 2; k++)
                for(int p = 0; p <= s; p++){
                    if (!dp[id ^ 1][j][k][p])
                        continue;
                    int nxtK = k;
                    int nxtP = p;
                    nextState(nxtK, nxtP, a[i + 1][j + 1]);
                    add(dp[id ^ 1][j + 1][nxtK][nxtP], dp[id ^ 1][j][k][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

mobitel.cpp: In function 'void readInput()':
mobitel.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     scanf("%d %d %d", &r, &c, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mobitel.cpp:24:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |             scanf("%d", &a[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~
mobitel.cpp: In function 'int main()':
mobitel.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   82 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
mobitel.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   83 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 67 ms 5624 KB Output is correct
2 Correct 70 ms 5636 KB Output is correct
3 Correct 164 ms 2048 KB Output is correct
4 Correct 175 ms 2048 KB Output is correct
5 Correct 337 ms 2168 KB Output is correct
6 Correct 311 ms 2048 KB Output is correct
7 Correct 133 ms 1536 KB Output is correct
8 Correct 1857 ms 4216 KB Output is correct
9 Correct 3466 ms 5576 KB Output is correct
10 Correct 3520 ms 5624 KB Output is correct