Can anyone please provide me with hints for the practice problem of this contest? Link
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 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.
Название |
---|