답안 #703058

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703058 2023-02-25T20:20:10 Z rainboy K번째 경로 (IZhO11_kthpath) C
0 / 100
1 ms 296 KB
#include <stdio.h>
#include <string.h>

#define N	30
#define M	30

int main() {
	static char cc[N][M + 1], aa[N + M];
	static long long dp[N][M][2];
	int n, m, h, i, j;
	long long k;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		scanf("%s", cc[i]);
	scanf("%lld", &k);
	memset(aa, 'a', (n + m - 1) * sizeof *aa);
	for (h = 0; h < n + m - 1; h++) {
		for (aa[h] = 'a'; aa[h] < 'z'; aa[h]++) {
			for (i = 0; i < n; i++)
				for (j = 0; j < m; j++)
					dp[i][j][0] = dp[i][j][1] = 0;
			if (cc[0][0] == aa[0])
				dp[0][0][0] = 1;
			else if (cc[0][0] < aa[0])
				dp[0][0][1] = 1;
			for (i = 0; i < n; i++)
				for (j = 0; j < m; j++) {
					long long x;

					if ((x = dp[i][j][0]) != 0) {
						if (i + 1 < n) {
							if (cc[i + 1][j] == aa[i + j + 1])
								dp[i + 1][j][0] += x;
							else if (cc[i + 1][j] < aa[i + j + 1])
								dp[i + 1][j][1] += x;
						}
						if (j + 1 < m) {
							if (cc[i][j + 1] == aa[i + j + 1])
								dp[i][j + 1][0] += x;
							else if (cc[i][j + 1] < aa[i + j + 1])
								dp[i][j + 1][1] += x;
						}
					}
					if ((x = dp[i][j][1]) != 0) {
						if (i + 1 < n)
							dp[i + 1][j][1] += x;
						if (j + 1 < m)
							dp[i][j + 1][1] += x;
					}
				}
			if (dp[n - 1][m - 1][1] >= k)
				break;
		}
		aa[h]--;
	}
	printf("%s\n", aa);
	return 0;
}

Compilation message

kthpath.c: In function 'main':
kthpath.c:13:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
kthpath.c:15:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   scanf("%s", cc[i]);
      |   ^~~~~~~~~~~~~~~~~~
kthpath.c:16:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf("%lld", &k);
      |  ^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 296 KB Output isn't correct
4 Halted 0 ms 0 KB -