답안 #410731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
410731 2021-05-23T14:19:53 Z snasibov05 Go (COCI18_go) C++14
60 / 100
607 ms 524292 KB
#include <iostream>
#include <vector>

using namespace std;

struct data{
    int x;
    int c;
    int t;
};

const int tmax = 2005;

int calc(int l, int r, int t, int lst, int n,vector<data>& v, vector<vector<vector<vector<int>>>>& dp){

    if (t >= tmax || l < 0 || r >= n) return 0;
    if (dp[l][r][t][lst] != -1) return dp[l][r][t][lst];

    int res = 0;
    if (lst == 0){
        res = max(res, calc(l-1, r, t + (v[l].x - v[l-1].x), 0, n,  v, dp));
        res = max(res, calc(l, r+1, t + (v[r+1].x - v[l].x), 1, n, v, dp));
        if (t < v[l].t) res += v[l].c;
    } else{
        res = max(res, calc(l-1, r, t + (v[r].x - v[l-1].x), 0, n, v, dp));
        res = max(res, calc(l, r+1, t + (v[r+1].x - v[r].x), 1, n, v, dp));
        if (t < v[r].t) res += v[r].c;
    }

    return dp[l][r][t][lst] = res;

}

int main() {

    int n, k, m; cin >> n >> k >> m;
    vector<data> v(n);
    for (int i = 0; i < m; ++i) {
        cin >> v[i].x >> v[i].c >> v[i].t;
    }

    vector<vector<vector<vector<int>>>> dp(m, vector<vector<vector<int>>>(m, vector<vector<int>>(tmax+5, vector<int>(2, -1))));

    int ans = 0;
    for (int i = 0; i < m; ++i){
        ans = max(ans, calc(i, i, abs(k - v[i].x), 0, m, v, dp));
    }

    cout << ans << "\n";



    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2532 KB Output is correct
2 Correct 16 ms 12448 KB Output is correct
3 Correct 31 ms 23420 KB Output is correct
4 Correct 62 ms 46656 KB Output is correct
5 Correct 490 ms 281468 KB Output is correct
6 Correct 607 ms 403624 KB Output is correct
7 Runtime error 513 ms 524292 KB Execution killed with signal 9
8 Runtime error 497 ms 524292 KB Execution killed with signal 9
9 Runtime error 503 ms 524292 KB Execution killed with signal 9
10 Runtime error 477 ms 524292 KB Execution killed with signal 9