Submission #397861

# Submission time Handle Problem Language Result Execution time Memory
397861 2021-05-03T09:59:43 Z maomao90 Journey (NOI18_journey) C++14
100 / 100
78 ms 35488 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair <int, int> ii;

#define INF 500000001

int n, m, h;
vector <ii> adjList[10005];

long long memo[10005][405];
long long dp(int index, int rem) {
	if (index >= n - 1) {
		if (rem == 0) return 1;
		else return 0;
	}
	if (rem < 0) return 0;
	if (memo[index][rem] != -1) return memo[index][rem];

	long long cur = 0;
	cur += dp(index, rem - 1);
	if (cur >= INF) return memo[index][rem] = INF;
	for (ii vw : adjList[index]) {
		int v, w; tie(v, w) = vw;
		cur += dp(v, rem - w);
		if (cur >= INF) return memo[index][rem] = INF;
	}
	return memo[index][rem] = cur;
}

int main() {
	scanf("%d%d%d", &n, &m, &h);
	for (int i = 0; i < n - 1; i++) {
		for (int jj = 0; jj < h; jj++) {
			int j, k; scanf("%d%d", &j, &k);
			if (j <= i) continue;
			adjList[i].emplace_back(j, k);
		}
	}
	memset(memo, -1, sizeof memo);
	for (int i = 0; i < m; i++) {
		printf("%lld ", dp(0, i));
	}
	printf("\n");
	return 0;
}

Compilation message

journey.cpp: In function 'int main()':
journey.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |  scanf("%d%d%d", &n, &m, &h);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
journey.cpp:35:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |    int j, k; scanf("%d%d", &j, &k);
      |              ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 32204 KB Output is correct
2 Correct 14 ms 32204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 32204 KB Output is correct
2 Correct 14 ms 32208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 32204 KB Output is correct
2 Correct 14 ms 32204 KB Output is correct
3 Correct 15 ms 32204 KB Output is correct
4 Correct 14 ms 32208 KB Output is correct
5 Correct 16 ms 32204 KB Output is correct
6 Correct 16 ms 32192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 32204 KB Output is correct
2 Correct 14 ms 32204 KB Output is correct
3 Correct 15 ms 32204 KB Output is correct
4 Correct 14 ms 32208 KB Output is correct
5 Correct 16 ms 32204 KB Output is correct
6 Correct 16 ms 32192 KB Output is correct
7 Correct 78 ms 35488 KB Output is correct
8 Correct 49 ms 34244 KB Output is correct
9 Correct 22 ms 32460 KB Output is correct
10 Correct 31 ms 33484 KB Output is correct