Submission #707283

# Submission time Handle Problem Language Result Execution time Memory
707283 2023-03-08T17:58:17 Z aedmhsn Go (COCI18_go) C++17
70 / 100
156 ms 173004 KB
#include <bits/stdc++.h>
using namespace std;
 
 
#define A first
#define B second
#define MP make_pair
#define ms(a, x) memset(a, x, sizeof(a)) 
 
 
#define boost() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pld;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);

const int mxN=5e3+5;

int dp[105][105][2000][2], t[105], v[105], h[105], n, m, k;

// left = 1, right = 0;
int solve(int l, int r, int time, bool dir){
    if(dp[l][r][time][dir] != -1)
        return dp[l][r][time][dir];
    int ret1=0, ret2=0;
    if(dir){
        if(l-1 >= 1)
            ret1 = solve(l-1, r, time+abs(h[l]-h[l-1]), 1)+(time + abs(h[l]-h[l-1]) < t[l-1] ? v[l-1]:0);
        if(r <= m)
            ret2 = solve(l-1, r, time+abs(h[l]-h[r]), 0) + (time + abs(h[l]-h[r]) < t[r] ? v[r]:0);
        
        return dp[l][r][time][dir]=max(ret1, ret2);
    }
    else{
        if(l >= 1)
            ret1 = solve(l, r+1, time+abs(h[r]-h[l]), 1)+(time + abs(h[r]-h[l]) < t[l] ? v[l]:0);
        if(r+1 <= m)
            ret2 = solve(l, r+1, time+abs(h[r]-h[r+1]), 0) + (time + abs(h[r]-h[r+1]) < t[r+1] ? v[r+1]:0);
        return dp[l][r][time][dir]=max(ret1, ret2);
    }

}

int main(){
    ms(dp , -1);
    cin >> n >> k >> m;
    int st=-1;
    for(int i=1; i<=m; i++){
        cin >> h[i] >> v[i] >> t[i];
        if(h[i] >= k && st==-1)
            st=i;
    }
    if(st == -1)
        cout << solve(m-1, m, (k-h[m]), 0) + (abs(k-h[m]) < t[m] ? v[m]:0);
    else
        cout << max(solve(st-1, st, abs(k-h[st-1]), 1)+(abs(k-h[st-1]) < t[st-1] ? v[st-1]:0), solve(st-1, st, abs(k-h[st]), 0) + (abs(k-h[st]) < t[st] ? v[st]:0));
}
# Verdict Execution time Memory Grader output
1 Correct 60 ms 172876 KB Output is correct
2 Correct 69 ms 172832 KB Output is correct
3 Correct 67 ms 172768 KB Output is correct
4 Correct 64 ms 172876 KB Output is correct
5 Incorrect 89 ms 172836 KB Output isn't correct
6 Correct 73 ms 172860 KB Output is correct
7 Correct 124 ms 172896 KB Output is correct
8 Correct 156 ms 172796 KB Output is correct
9 Incorrect 134 ms 173004 KB Output isn't correct
10 Incorrect 119 ms 172788 KB Output isn't correct