This question was asked was in an OA. I was not able to sovle it fully i.e my soln got partially accepted.
Question
Code
I want to solve this problem via memorization as I am not so good at writing bottom-up approach directly.
Thanks in advance.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3773 |
3 | Radewoosh | 3646 |
4 | ecnerwala | 3624 |
5 | jqdai0815 | 3620 |
5 | Benq | 3620 |
7 | orzdevinwang | 3612 |
8 | Geothermal | 3569 |
8 | cnnfls_csy | 3569 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | Um_nik | 162 |
2 | cry | 161 |
3 | maomao90 | 160 |
4 | -is-this-fft- | 159 |
5 | awoo | 158 |
6 | atcoder_official | 157 |
7 | nor | 155 |
7 | adamant | 155 |
9 | maroonrk | 152 |
10 | Dominater069 | 149 |
Online assessment Question --> How to apply dp to such large constraints
This question was asked was in an OA. I was not able to sovle it fully i.e my soln got partially accepted.
ll getDistance(ll x1, ll y1, ll x2, ll y2)
{
return (abs(x1 - x2) + abs(y1 - y2));
}
ll func(ll ax, ll ay, ll bx, ll by, ll idx, vvi &corr)
{
if (idx == corr.size()) return 0;
vector<ll>pos = corr[idx];
ll x1 = pos[0], y1 = pos[1];
ll alice = getDistance(ax, ay, x1, y1) + func(x1, y1, bx, by, idx + 1, corr);
ll bob = getDistance(bx, by, x1, y1) + func(ax, ay, x1, y1, idx + 1, corr);
return min(alice, bob);
}
void getAns(ll n, ll ax, ll ay, ll bx, ll by, vvi &corr)
{
ll ans = func(ax, ay, bx, by, 0, corr);
cout << ans << line;
}
void solve()
{
ll n, ax, ay, bx, by;
cin >> n >> ax >> ay >> bx >> by;
vvi corr;
f(i, 0, n)
{
ll x, y;
cin >> x >> y;
vi v;
v.pb(x);
v.pb(y);
corr.pb(v);
}
getAns(n, ax, ay, bx, by, corr);
}
I want to solve this problem via memorization as I am not so good at writing bottom-up approach directly.
Thanks in advance.
Rev. | Язык | Кто | Когда | Δ | Комментарий | |
---|---|---|---|---|---|---|
en3 | wronganswer.5 | 2023-06-21 10:55:51 | 110 | |||
en2 | wronganswer.5 | 2023-06-21 10:54:05 | 98 | |||
en1 | wronganswer.5 | 2023-06-21 10:49:58 | 1341 | Initial revision (published) |
Название |
---|