답안 #792874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792874 2023-07-25T10:12:56 Z IvanJ Fireworks (APIO16_fireworks) C++17
19 / 100
27 ms 716 KB
#include<bits/stdc++.h>

#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()

using namespace std;

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

const int maxn = 305;

int n, m;
int dp[maxn][maxn];
vector<ii> adj[maxn];

int rek(int x, int len) {
	if(dp[x][len] != -1)
		return dp[x][len];
	if(adj[x].size() == 0)
		return dp[x][len] = (len == 0) ? 0 : 1e9;
	
	int ret = 0;
	for(auto p : adj[x]) {
		int reti = 1e9;
		for(int i = 0;i <= len;i++) {
			int l = len - i;
			reti = min(reti, rek(p.x, i) + abs(p.y - l));
		}
		ret += reti;
	}
	return dp[x][len] = ret;
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1;i < n + m;i++) {
		int p, c;
		scanf("%d%d", &p, &c);
		p--;
		adj[p].pb({i, c});
	}
	
	memset(dp, -1, sizeof dp);
	int ans = 1e9;
	for(int i = 0;i < maxn;i++) 
		ans = min(ans, rek(0, i));
	printf("%d\n", ans);
	return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
fireworks.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%d%d", &p, &c);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 572 KB Output is correct
2 Correct 3 ms 572 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
4 Correct 6 ms 596 KB Output is correct
5 Correct 7 ms 596 KB Output is correct
6 Correct 9 ms 676 KB Output is correct
7 Correct 9 ms 572 KB Output is correct
8 Correct 12 ms 680 KB Output is correct
9 Correct 10 ms 596 KB Output is correct
10 Correct 12 ms 680 KB Output is correct
11 Correct 13 ms 680 KB Output is correct
12 Correct 14 ms 596 KB Output is correct
13 Correct 15 ms 676 KB Output is correct
14 Correct 19 ms 716 KB Output is correct
15 Correct 17 ms 680 KB Output is correct
16 Correct 16 ms 596 KB Output is correct
17 Correct 16 ms 596 KB Output is correct
18 Correct 27 ms 596 KB Output is correct
19 Correct 16 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -