Can anyone please provide me with hints for the practice problem of this contest? Link
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
Can anyone please provide me with hints for the practice problem of this contest? Link
I am moving from python to c++ and am facing some issues. In this recent Atcoder Beginner problem, I am getting TLE.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for(int i=0; i<n; i++)
const int p = 5;
ll dp[100001][p];
ll helper(ll time, ll pos, map<pair<ll, ll>, ll> &snuke){
if (time > 10|| pos < 0 || pos > 4) return 0;
if (dp[time][pos] != 0) return dp[time][pos];
ll first, second, third;
first = helper(time+1, pos-1, snuke);
second = helper(time+1, pos+1, snuke);
third = helper(time+1, pos, snuke);
ll ans = max(first, second);
ans = max(ans, third);
dp[time][pos] = ans;
if (snuke.count(make_pair(time, pos)) != 0)
dp[time][pos] += snuke[{time, pos}];
return dp[time][pos];
}
void solve(){
int n;
cin >> n;
map<pair<ll, ll>, ll> snuke;
forn(i, n){
ll t, x, a;
cin >> t >> x >> a;
snuke.insert(make_pair(make_pair(t, x), a));
}
cout << helper(0, 0, snuke);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
}
I was solving problem H of a div 4 round. The first solution I wrote got MLE so in order to save some memory I decided to use arrays instead of lists, this got me a wrong answer in test 4 (solution), can anyone explain why did that happen. Looks like the program stopped executing after the first test case.
Name |
---|