Submission #404264

# Submission time Handle Problem Language Result Execution time Memory
404264 2021-05-14T03:28:43 Z jeqcho Fireworks (APIO16_fireworks) C++17
0 / 100
2000 ms 27668 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define fi first
#define se second

int const NM=3e2+3;
bitset<NM> bomb;
int v[NM];
vpi adj[NM];
int const pad=NM;
ll dp[NM][NM][NM+pad];
bitset<NM+pad> vis[NM][NM];

void dfs1(int now, int w)
{
	if(bomb[now])
	{
		v[now] = w;
	}
	trav(chi,adj[now])
	{
		dfs1(chi.fi, w+chi.se);
	}
}

ll dfs2(int now, int x, int chn, int w)
{
	if(vis[now][x][chn+pad])return dp[now][x][chn+pad];
	vis[now][x][chn+pad]=1;
	dp[now][x][chn+pad]=1e9;
	F0R(i,300+3)
	{
		ll cost = abs(i-w);
		ll chn2 = chn+i-w;
		if(chn2>x)break;
		ll cand = cost;
		if(bomb[now] && v[now]+chn2 != x)
		{
			cand=1e8;
		}
		trav(chi,adj[now])
		{
			cand += dfs2(chi.fi,x,chn2,chi.se);
		}
		dp[now][x][chn+pad] = min(dp[now][x][chn+pad],cand);
	}
	return dp[now][x][chn+pad];
}

ll to(int x)
{
	return dfs2(0,x,0,0);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m;
	cin>>n>>m;
	FOR(i,1,n+m)
	{
		int p,c;
		cin>>p>>c;
		--p;
		adj[p].pb({i,c});
		if(i>=n)
		{
			bomb[i]=1;
		}
	}
	dfs1(0,0);
	ll mn=1e18;
	F0R(i,300+3)
	{
		mn=min(to(i),mn);
	}
	cout<<mn<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 70 ms 2884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1175 ms 18836 KB Output is correct
2 Execution timed out 2089 ms 27668 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 70 ms 2884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 70 ms 2884 KB Output isn't correct
2 Halted 0 ms 0 KB -