답안 #672262

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672262 2022-12-15T09:19:13 Z Dan4Life Fireworks (APIO16_fireworks) C++17
19 / 100
21 ms 1268 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define sz(a) (int)a.size()
const int maxn = 5e3+10;
const int LINF = (int)1e18;
int p[maxn], c[maxn];
int n, m, ans;
vector<pair<int,int>> adj[maxn];
int dp[maxn][310];
bool ok[maxn][310];

void dfs(int s, int p){
	if(s>n){ dp[s][0]=0;ok[s][0]=1; return; }
	for(auto cur : adj[s]){
		int u = cur.fi, c = cur.se;
		if(u==p) continue; dfs(u,s);
		for(int i = 0; i <= 300; i++){
			int price = LINF;
			for(int j = 0; j <= i; j++)
				if(ok[u][j]) price = min(price, abs(c-(i-j))+dp[u][j]);
			if(price==LINF) ok[s][i]=false;
			else dp[s][i]+=price;
		}
	}
}

int32_t main() {
	cin >> n >> m; ans=LINF;
	for(int i = 2; i <= n+m; i++){
		cin >> p[i] >> c[i];
		adj[i].pb({p[i],c[i]});
		adj[p[i]].pb({i,c[i]});
	}
	for(int i = 1; i <= n; i++)
		for(int j = 0; j <= 300; j++)
			ok[i][j]=1;
	dfs(1,1);
	for(int i = 0; i <= 300; i++) if(ok[1][i]) ans=min(ans, dp[1][i]); cout << ans;
}

Compilation message

fireworks.cpp: In function 'void dfs(long long int, long long int)':
fireworks.cpp:22:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   22 |   if(u==p) continue; dfs(u,s);
      |   ^~
fireworks.cpp:22:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   22 |   if(u==p) continue; dfs(u,s);
      |                      ^~~
fireworks.cpp: In function 'int32_t main()':
fireworks.cpp:44:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   44 |  for(int i = 0; i <= 300; i++) if(ok[1][i]) ans=min(ans, dp[1][i]); cout << ans;
      |  ^~~
fireworks.cpp:44:69: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   44 |  for(int i = 0; i <= 300; i++) if(ok[1][i]) ans=min(ans, dp[1][i]); cout << ans;
      |                                                                     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 2 ms 428 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
4 Correct 10 ms 660 KB Output is correct
5 Correct 9 ms 724 KB Output is correct
6 Correct 7 ms 724 KB Output is correct
7 Correct 8 ms 852 KB Output is correct
8 Correct 11 ms 852 KB Output is correct
9 Correct 12 ms 972 KB Output is correct
10 Correct 13 ms 1040 KB Output is correct
11 Correct 12 ms 980 KB Output is correct
12 Correct 18 ms 1144 KB Output is correct
13 Correct 14 ms 1108 KB Output is correct
14 Correct 17 ms 1224 KB Output is correct
15 Correct 16 ms 1200 KB Output is correct
16 Correct 21 ms 1256 KB Output is correct
17 Correct 19 ms 1268 KB Output is correct
18 Correct 14 ms 1260 KB Output is correct
19 Correct 14 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -