Submission #45167

# Submission time Handle Problem Language Result Execution time Memory
45167 2018-04-11T15:20:40 Z erdemkiraz Fireworks (APIO16_fireworks) C++11
19 / 100
31 ms 1020 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int, int > ii;

const int N = 300 + 5;

int n, m;
vector < ii > v[N];
int dp[N][N], dp2[N];

int main() {

	scanf("%d %d", &n, &m);

	for(int i = 2; i <= n + m; i++) {
		int x, c;
		scanf("%d %d", &x, &c);
		v[x].push_back({i, c});
	}

	for(int i = n + 1; i <= n + m; i++) {
		for(int j = 1; j < N; j++)
			dp[i][j] = 1e9;
	}

	for(int x = n; x >= 1; x--) {
		for(auto u : v[x]) {
			for(int i = 0; i < N; i++)
				dp2[i] = 1e9;
			for(int i = 0; i < N; i++)
				for(int j = -u.second; i - j - u.second >= 0; j++)
					dp2[i] = min(dp2[i], dp[u.first][i - j - u.second] + abs(j));
			for(int i = 0; i < N; i++)
				dp[x][i] += dp2[i];
		}
	}

	int res = 1e9;

	for(int i = 0; i < N; i++) {
		res = min(res, dp[1][i]);
	}

	printf("%d\n", res);

    return 0;

}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
fireworks.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &x, &c);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 488 KB Output is correct
2 Correct 5 ms 544 KB Output is correct
3 Correct 8 ms 544 KB Output is correct
4 Correct 9 ms 648 KB Output is correct
5 Correct 10 ms 692 KB Output is correct
6 Correct 11 ms 700 KB Output is correct
7 Correct 13 ms 724 KB Output is correct
8 Correct 14 ms 740 KB Output is correct
9 Correct 15 ms 744 KB Output is correct
10 Correct 16 ms 760 KB Output is correct
11 Correct 18 ms 884 KB Output is correct
12 Correct 20 ms 884 KB Output is correct
13 Correct 23 ms 996 KB Output is correct
14 Correct 23 ms 996 KB Output is correct
15 Correct 25 ms 996 KB Output is correct
16 Correct 31 ms 996 KB Output is correct
17 Correct 23 ms 996 KB Output is correct
18 Correct 24 ms 1020 KB Output is correct
19 Correct 23 ms 1020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -