# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
409647 | 2021-05-21T09:23:43 Z | juggernaut | Fireworks (APIO16_fireworks) | C++17 | 29 ms | 15272 KB |
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} typedef long long ll; #define USING_ORDERED_SET 0 #if USING_ORDERED_SET #include<bits/extc++.h> using namespace __gnu_pbds; template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #endif template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef IOI2021SG #define printl(args...)printf(args) #else #define printl(args...)((void)0) #endif vector<pair<int,int>>g[300005]; int dp[305][305],n,m; void dfs(int v){ if(v>n){ dp[v][0]=0; for(int i=1;i<=300;i++)dp[v][i]=1e9; return; } for(auto &[to,w]:g[v]){ dfs(to); for(int i=0;i<=300;i++){ int mn=1e7; for(int j=0;j<=i;j++)umin(mn,dp[to][j]+abs(i-j-w)); dp[v][i]+=mn; } } } int main(){ scanf("%d%d",&n,&m); if(n==1){ vector<int>v; for(int i=2;i<=n+m;i++){ int x,y; scanf("%d%d",&x,&y); v.push_back(y); } ll ans=9e18; for(int x:v){ ll cnt=0; for(int y:v)cnt+=abs(x-y); umin(ans,cnt); } printf("%lld",ans); exit(0); } for(int i=2;i<=n+m;i++){ int x,y; scanf("%d%d",&x,&y); g[x].emplace_back(i,y); } dfs(1); int ans=2e9; for(int i=0;i<=300;i++)umin(ans,dp[1][i]); printf("%d",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7244 KB | Output is correct |
2 | Correct | 4 ms | 7244 KB | Output is correct |
3 | Correct | 4 ms | 7244 KB | Output is correct |
4 | Correct | 4 ms | 7244 KB | Output is correct |
5 | Correct | 6 ms | 7244 KB | Output is correct |
6 | Correct | 5 ms | 7244 KB | Output is correct |
7 | Correct | 4 ms | 7244 KB | Output is correct |
8 | Correct | 5 ms | 7244 KB | Output is correct |
9 | Correct | 5 ms | 7244 KB | Output is correct |
10 | Correct | 5 ms | 7244 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7244 KB | Output is correct |
2 | Correct | 6 ms | 7380 KB | Output is correct |
3 | Correct | 8 ms | 7360 KB | Output is correct |
4 | Correct | 10 ms | 7372 KB | Output is correct |
5 | Correct | 12 ms | 7436 KB | Output is correct |
6 | Correct | 12 ms | 7500 KB | Output is correct |
7 | Correct | 14 ms | 7500 KB | Output is correct |
8 | Correct | 15 ms | 7500 KB | Output is correct |
9 | Correct | 15 ms | 7500 KB | Output is correct |
10 | Correct | 19 ms | 7604 KB | Output is correct |
11 | Correct | 18 ms | 7620 KB | Output is correct |
12 | Correct | 20 ms | 7628 KB | Output is correct |
13 | Correct | 21 ms | 7628 KB | Output is correct |
14 | Correct | 22 ms | 7628 KB | Output is correct |
15 | Correct | 22 ms | 7696 KB | Output is correct |
16 | Correct | 22 ms | 7676 KB | Output is correct |
17 | Correct | 21 ms | 7628 KB | Output is correct |
18 | Correct | 29 ms | 7604 KB | Output is correct |
19 | Correct | 22 ms | 7684 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7244 KB | Output is correct |
2 | Correct | 4 ms | 7244 KB | Output is correct |
3 | Correct | 4 ms | 7244 KB | Output is correct |
4 | Correct | 4 ms | 7244 KB | Output is correct |
5 | Correct | 6 ms | 7244 KB | Output is correct |
6 | Correct | 5 ms | 7244 KB | Output is correct |
7 | Correct | 4 ms | 7244 KB | Output is correct |
8 | Correct | 5 ms | 7244 KB | Output is correct |
9 | Correct | 5 ms | 7244 KB | Output is correct |
10 | Correct | 5 ms | 7244 KB | Output is correct |
11 | Correct | 5 ms | 7244 KB | Output is correct |
12 | Correct | 6 ms | 7380 KB | Output is correct |
13 | Correct | 8 ms | 7360 KB | Output is correct |
14 | Correct | 10 ms | 7372 KB | Output is correct |
15 | Correct | 12 ms | 7436 KB | Output is correct |
16 | Correct | 12 ms | 7500 KB | Output is correct |
17 | Correct | 14 ms | 7500 KB | Output is correct |
18 | Correct | 15 ms | 7500 KB | Output is correct |
19 | Correct | 15 ms | 7500 KB | Output is correct |
20 | Correct | 19 ms | 7604 KB | Output is correct |
21 | Correct | 18 ms | 7620 KB | Output is correct |
22 | Correct | 20 ms | 7628 KB | Output is correct |
23 | Correct | 21 ms | 7628 KB | Output is correct |
24 | Correct | 22 ms | 7628 KB | Output is correct |
25 | Correct | 22 ms | 7696 KB | Output is correct |
26 | Correct | 22 ms | 7676 KB | Output is correct |
27 | Correct | 21 ms | 7628 KB | Output is correct |
28 | Correct | 29 ms | 7604 KB | Output is correct |
29 | Correct | 22 ms | 7684 KB | Output is correct |
30 | Runtime error | 24 ms | 15272 KB | Execution killed with signal 11 |
31 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7244 KB | Output is correct |
2 | Correct | 4 ms | 7244 KB | Output is correct |
3 | Correct | 4 ms | 7244 KB | Output is correct |
4 | Correct | 4 ms | 7244 KB | Output is correct |
5 | Correct | 6 ms | 7244 KB | Output is correct |
6 | Correct | 5 ms | 7244 KB | Output is correct |
7 | Correct | 4 ms | 7244 KB | Output is correct |
8 | Correct | 5 ms | 7244 KB | Output is correct |
9 | Correct | 5 ms | 7244 KB | Output is correct |
10 | Correct | 5 ms | 7244 KB | Output is correct |
11 | Correct | 5 ms | 7244 KB | Output is correct |
12 | Correct | 6 ms | 7380 KB | Output is correct |
13 | Correct | 8 ms | 7360 KB | Output is correct |
14 | Correct | 10 ms | 7372 KB | Output is correct |
15 | Correct | 12 ms | 7436 KB | Output is correct |
16 | Correct | 12 ms | 7500 KB | Output is correct |
17 | Correct | 14 ms | 7500 KB | Output is correct |
18 | Correct | 15 ms | 7500 KB | Output is correct |
19 | Correct | 15 ms | 7500 KB | Output is correct |
20 | Correct | 19 ms | 7604 KB | Output is correct |
21 | Correct | 18 ms | 7620 KB | Output is correct |
22 | Correct | 20 ms | 7628 KB | Output is correct |
23 | Correct | 21 ms | 7628 KB | Output is correct |
24 | Correct | 22 ms | 7628 KB | Output is correct |
25 | Correct | 22 ms | 7696 KB | Output is correct |
26 | Correct | 22 ms | 7676 KB | Output is correct |
27 | Correct | 21 ms | 7628 KB | Output is correct |
28 | Correct | 29 ms | 7604 KB | Output is correct |
29 | Correct | 22 ms | 7684 KB | Output is correct |
30 | Runtime error | 24 ms | 15272 KB | Execution killed with signal 11 |
31 | Halted | 0 ms | 0 KB | - |