Submission #479421

# Submission time Handle Problem Language Result Execution time Memory
479421 2021-10-11T17:57:22 Z rainboy Mobitel (COCI19_mobitel) C
91 / 130
287 ms 39920 KB
#include <stdio.h>

#define N	300
#define M	300
#define A	300
#define N_	100
#define M_	100
#define B	1000
#define MD	1000000007

int vv[N + M], ff[N + M], gg[N + M];

void init() {
	int i;

	ff[0] = gg[0] = 1;
	for (i = 1; i < N + M; i++) {
		vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
		ff[i] = (long long) ff[i - 1] * i % MD;
		gg[i] = (long long) gg[i - 1] * vv[i] % MD;
	}
}

int choose(int n, int k) {
	return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}

int main() {
	static int aa[N][M];
	int n, m, c, i, j, a, b, b1, b2, x, ans;

	init();
	scanf("%d%d%d", &n, &m, &c);
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			scanf("%d", &aa[i][j]);
	if (c == 1)
		ans = 0;
	else if (n <= N_ && m <= M_) {
		static int dp[N_][M_][B], dq[M_][B];

		for (i = 0; i < n; i++)
			for (j = 0; j < m; j++)
				if (i == 0 && j == 0)
					dp[i][j][1] = 1;
				else
					for (b = B - 1; b >= 1; b--) {
						dp[i][j][b] = 0;
						if (i > 0 && b % (a = aa[i - 1][j]) == 0)
							dp[i][j][b] = (dp[i][j][b] + dp[i - 1][j][b / a]) % MD;
						if (j > 0 && b % (a = aa[i][j - 1]) == 0)
							dp[i][j][b] = (dp[i][j][b] + dp[i][j - 1][b / a]) % MD;
					}
		a = aa[n - 1][m - 1];
		ans = 0;
		for (b = 0; b * a < c && b * a < B; b++)
			ans = (ans + dp[n - 1][m - 1][b]) % MD;
		for (i = n - 1; i >= 0; i--) {
			for (j = m - 1; j >= 0; j--)
				if (i == n - 1 && j == m - 1)
					dq[j][1] = 1;
				else
					for (b = B - 1; b >= 1; b--) {
						int x = dq[j][b];

						dq[j][b] = 0;
						if (i + 1 < n && b % (a = aa[i + 1][j]) == 0)
							dq[j][b] = (dq[j][b] + (a == 1 ? x : dq[j][b / a])) % MD;
						if (j + 1 < m && b % (a = aa[i][j + 1]) == 0)
							dq[j][b] = (dq[j][b] + dq[j + 1][b / a]) % MD;
					}
			for (j = m - 1; j >= 0; j--) {
				a = aa[i][j];
				for (b1 = B - 1, b2 = 1, x = 0; b1 * a >= B; b1--) {
					while (b2 < B && (long long) b1 * a * b2 < c)
						x = (x + dq[j][b2++]) % MD;
					ans = (ans + (long long) dp[i][j][b1] * x) % MD;
				}
			}
		}
	} else {
		static int dp[M][A];

		if (c > A) {
			printf("0\n");
			return 0;
		}
		for (i = 0; i < n; i++)
			for (j = 0; j < m; j++) {
				a = aa[i][j];
				if (i == 0 && j == 0) {
					if (a < c)
						dp[j][a] = 1;
				} else
					for (b = c - 1; b >= 1; b--)
						dp[j][b] = b % a == 0 ? ((i == 0 ? 0 : dp[j][b / a]) + (j == 0 ? 0 : dp[j - 1][b / a])) % MD : 0;
			}
		ans = 0;
		for (b = 1; b < c; b++)
			ans = (ans + dp[m - 1][b]) % MD;
	}
	ans = (choose(n - 1 + m - 1, n - 1) - ans + MD) % MD;
	printf("%d\n", ans);
	return 0;
}

Compilation message

mobitel.c: In function 'main':
mobitel.c:33:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  scanf("%d%d%d", &n, &m, &c);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
mobitel.c:36:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |    scanf("%d", &aa[i][j]);
      |    ^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 151 ms 972 KB Output is correct
2 Correct 164 ms 972 KB Output is correct
3 Correct 287 ms 39524 KB Output is correct
4 Correct 287 ms 39844 KB Output is correct
5 Correct 285 ms 39920 KB Output is correct
6 Correct 286 ms 39620 KB Output is correct
7 Correct 143 ms 20000 KB Output is correct
8 Incorrect 4 ms 460 KB Output isn't correct
9 Incorrect 8 ms 600 KB Output isn't correct
10 Incorrect 7 ms 588 KB Output isn't correct