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.
# | User | Rating |
---|---|---|
1 | tourist | 3845 |
2 | jiangly | 3707 |
3 | Benq | 3630 |
4 | orzdevinwang | 3573 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | jqdai0815 | 3532 |
8 | ecnerwala | 3501 |
9 | gyh20 | 3447 |
10 | Rebelz | 3409 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 171 |
2 | awoo | 163 |
2 | adamant | 163 |
4 | maroonrk | 152 |
5 | nor | 151 |
5 | -is-this-fft- | 151 |
7 | TheScrasse | 147 |
7 | atcoder_official | 147 |
9 | Petr | 145 |
10 | pajenegod | 144 |
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. | Lang. | By | When | Δ | Comment | |
---|---|---|---|---|---|---|
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) |
Name |
---|