Submission #796319

# Submission time Handle Problem Language Result Execution time Memory
796319 2023-07-28T09:25:53 Z Dan4Life Worst Reporter 4 (JOI21_worst_reporter4) C++17
14 / 100
418 ms 399948 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define all(a) begin(a),end(a)
const int mxN = (int)5e3+10;
const int LINF = (int)2e18;
int n, dp[mxN][mxN];
int a[mxN], h[mxN], c[mxN];
vector<int> adj[mxN];

int recur(int s, int v){
	if(v>=5001) return LINF;
	if(dp[s][v]!=-1) return dp[s][v];
	int ans = (v!=h[s])*c[s];
	for(auto u : adj[s]) ans+=recur(u,v);
	ans = min(ans, recur(s,v+1));
	return dp[s][v]=ans;
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n; vector<int> v;
	memset(dp,-1,sizeof(dp));
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> h[i] >> c[i];
		if(i>1) adj[a[i]].pb(i);
		v.pb(h[i]);
	}
	sort(all(v)); v.erase(unique(all(v)),end(v));
	for(int i = 1; i <= n; i++) h[i]=lower_bound(all(v),h[i])-begin(v);
	cout << recur(1,0);
}
# Verdict Execution time Memory Grader output
1 Correct 65 ms 197196 KB Output is correct
2 Correct 61 ms 197128 KB Output is correct
3 Correct 61 ms 197132 KB Output is correct
4 Correct 61 ms 197128 KB Output is correct
5 Correct 198 ms 197524 KB Output is correct
6 Correct 192 ms 197604 KB Output is correct
7 Correct 191 ms 197496 KB Output is correct
8 Correct 200 ms 197600 KB Output is correct
9 Correct 207 ms 197592 KB Output is correct
10 Correct 192 ms 197604 KB Output is correct
11 Correct 189 ms 197604 KB Output is correct
12 Correct 192 ms 197836 KB Output is correct
13 Correct 192 ms 197956 KB Output is correct
14 Correct 191 ms 197700 KB Output is correct
15 Correct 187 ms 197808 KB Output is correct
16 Correct 189 ms 197592 KB Output is correct
17 Correct 189 ms 197496 KB Output is correct
18 Correct 198 ms 197580 KB Output is correct
19 Correct 198 ms 197752 KB Output is correct
20 Correct 191 ms 197732 KB Output is correct
21 Correct 193 ms 197760 KB Output is correct
22 Correct 418 ms 197500 KB Output is correct
23 Correct 417 ms 197708 KB Output is correct
24 Correct 265 ms 197672 KB Output is correct
25 Correct 263 ms 197700 KB Output is correct
26 Correct 199 ms 197968 KB Output is correct
27 Correct 194 ms 197724 KB Output is correct
28 Correct 205 ms 197704 KB Output is correct
29 Correct 208 ms 197936 KB Output is correct
30 Correct 198 ms 197760 KB Output is correct
31 Correct 195 ms 197708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 197196 KB Output is correct
2 Correct 61 ms 197128 KB Output is correct
3 Correct 61 ms 197132 KB Output is correct
4 Correct 61 ms 197128 KB Output is correct
5 Correct 198 ms 197524 KB Output is correct
6 Correct 192 ms 197604 KB Output is correct
7 Correct 191 ms 197496 KB Output is correct
8 Correct 200 ms 197600 KB Output is correct
9 Correct 207 ms 197592 KB Output is correct
10 Correct 192 ms 197604 KB Output is correct
11 Correct 189 ms 197604 KB Output is correct
12 Correct 192 ms 197836 KB Output is correct
13 Correct 192 ms 197956 KB Output is correct
14 Correct 191 ms 197700 KB Output is correct
15 Correct 187 ms 197808 KB Output is correct
16 Correct 189 ms 197592 KB Output is correct
17 Correct 189 ms 197496 KB Output is correct
18 Correct 198 ms 197580 KB Output is correct
19 Correct 198 ms 197752 KB Output is correct
20 Correct 191 ms 197732 KB Output is correct
21 Correct 193 ms 197760 KB Output is correct
22 Correct 418 ms 197500 KB Output is correct
23 Correct 417 ms 197708 KB Output is correct
24 Correct 265 ms 197672 KB Output is correct
25 Correct 263 ms 197700 KB Output is correct
26 Correct 199 ms 197968 KB Output is correct
27 Correct 194 ms 197724 KB Output is correct
28 Correct 205 ms 197704 KB Output is correct
29 Correct 208 ms 197936 KB Output is correct
30 Correct 198 ms 197760 KB Output is correct
31 Correct 195 ms 197708 KB Output is correct
32 Correct 210 ms 197580 KB Output is correct
33 Runtime error 249 ms 399948 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 65 ms 197196 KB Output is correct
2 Correct 61 ms 197128 KB Output is correct
3 Correct 61 ms 197132 KB Output is correct
4 Correct 61 ms 197128 KB Output is correct
5 Correct 198 ms 197524 KB Output is correct
6 Correct 192 ms 197604 KB Output is correct
7 Correct 191 ms 197496 KB Output is correct
8 Correct 200 ms 197600 KB Output is correct
9 Correct 207 ms 197592 KB Output is correct
10 Correct 192 ms 197604 KB Output is correct
11 Correct 189 ms 197604 KB Output is correct
12 Correct 192 ms 197836 KB Output is correct
13 Correct 192 ms 197956 KB Output is correct
14 Correct 191 ms 197700 KB Output is correct
15 Correct 187 ms 197808 KB Output is correct
16 Correct 189 ms 197592 KB Output is correct
17 Correct 189 ms 197496 KB Output is correct
18 Correct 198 ms 197580 KB Output is correct
19 Correct 198 ms 197752 KB Output is correct
20 Correct 191 ms 197732 KB Output is correct
21 Correct 193 ms 197760 KB Output is correct
22 Correct 418 ms 197500 KB Output is correct
23 Correct 417 ms 197708 KB Output is correct
24 Correct 265 ms 197672 KB Output is correct
25 Correct 263 ms 197700 KB Output is correct
26 Correct 199 ms 197968 KB Output is correct
27 Correct 194 ms 197724 KB Output is correct
28 Correct 205 ms 197704 KB Output is correct
29 Correct 208 ms 197936 KB Output is correct
30 Correct 198 ms 197760 KB Output is correct
31 Correct 195 ms 197708 KB Output is correct
32 Correct 210 ms 197580 KB Output is correct
33 Runtime error 249 ms 399948 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -