Can anyone please provide me with hints for the practice problem of this contest? Link
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3821 |
3 | Benq | 3736 |
4 | Radewoosh | 3631 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3388 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
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 |
---|