Submission #156104

# Submission time Handle Problem Language Result Execution time Memory
156104 2019-10-03T11:38:15 Z Flying_dragon_02 도장 모으기 (JOI14_stamps) C++14
0 / 100
274 ms 212472 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;

const int mod = 1e9 + 7;

const int inf = 1e16;

const int N = 3005;

int add(int x, int y) {
    return (1ll * x + 1ll * y) % mod;
}

int del(int x, int y) {
    return ((1ll * x - 1ll * y) % mod + mod) % mod;
}

int mul(int x, int y) {
    return (1ll * x * 1ll * y) % mod;
}

int dp[N][N], n, t, u[N], v[N], d[N], e[N], f[N][N], f1[N][N];

signed main() {
    cin.tie(0), ios_base::sync_with_stdio(0);
    cin >> n >> t;
    for(int i = 1; i <= n; i++)
        cin >> u[i] >> v[i] >> d[i] >> e[i];
    //u[i] = nha cho len doc den cot tem
    //v[i] = cot tem den nha cho tau len doc
    //d[i] = nha cho tau xuong doc den cot tem
    //e[i] = cot tem den nha tau xuong doc
    for(int i = 0; i <= n + 1; i++) {
        for(int j = 0; j <= n + 1; j++) {
            dp[i][j] = inf;

        }
    }
    dp[0][0] = 0;
    for(int i = 0; i <= n + 1; i++) {
        if(i > 0) {
            for(int j = 0; j <= n + 1; j++) {
                if(j)
                    dp[i][j] = min(dp[i][j], dp[i - 1][j] + d[i] + e[i] + 2 * j * t);
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + u[i] + v[i] + 2 * j * t);
                if(j + 1 <= n + 1)
                    dp[i][j] = min(dp[i][j], f1[i - 1][j + 1] - j * (u[i] + e[i]));
                if(j)
                    dp[i][j] = min(dp[i][j], f[i - 1][j - 1] + j * (d[i] + v[i]));
                dp[i][j] += t;
//                cout << dp[i][j] << " " << i << " " << j << "\n";
            }
        }
        for(int j = 0; j <= n + 1; j++) {
            f[i][j] = dp[i][j] + 2 * j * t - j * (d[i + 1] + v[i + 1]);
            if(j)
                f[i][j] = min(f[i][j], f[i][j - 1]);
        }
        for(int j = n + 1; j >= 0; j--) {
            f1[i][j] = dp[i][j] + 2 * j * t + j * (u[i + 1] + e[i + 1]);
            if(j + 1 <= n + 1)
                f1[i][j] = min(f1[i][j], f1[i][j + 1]);
        }
    }
    cout << dp[n + 1][0];
}

/*4 1
1 1 1 1
1 9 9 1
9 9 1 1
1 9 9 1*/
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1656 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 1788 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Incorrect 2 ms 760 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 274 ms 212036 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 274 ms 212472 KB Output is correct
4 Correct 232 ms 187344 KB Output is correct
5 Correct 189 ms 155256 KB Output is correct
6 Incorrect 85 ms 72152 KB Output isn't correct
7 Halted 0 ms 0 KB -