답안 #707293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
707293 2023-03-08T18:04:57 Z aedmhsn Go (COCI18_go) C++17
70 / 100
197 ms 173440 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][2005][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(l-(dir) >= 1)
        ret1 = solve(l-dir, r+(!dir), time+abs(h[(dir ? l:r)]-h[l-dir]), 1)+(time + abs(h[(dir ? l:r)]-h[l-dir]) < t[l-dir] ? v[l-dir]:0);
    if(r+(!dir) <= m)
        ret2 = solve(l-dir, r+(!dir), time+abs(h[(dir ? l:r)]-h[r+(!dir)]), 0) + (time + abs(h[(dir ? l:r)]-h[r+(!dir)]) < t[r+(!dir)] ? v[r+(!dir)]: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));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 173248 KB Output is correct
2 Correct 67 ms 173300 KB Output is correct
3 Correct 64 ms 173296 KB Output is correct
4 Correct 64 ms 173288 KB Output is correct
5 Incorrect 90 ms 173316 KB Output isn't correct
6 Correct 74 ms 173244 KB Output is correct
7 Incorrect 166 ms 173440 KB Output isn't correct
8 Correct 159 ms 173320 KB Output is correct
9 Incorrect 174 ms 173420 KB Output isn't correct
10 Correct 197 ms 173260 KB Output is correct