Can anyone please provide me with hints for the practice problem of this contest? Link
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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 |
---|