답안 #361513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
361513 2021-01-30T10:33:47 Z Lam_lai_cuoc_doi 도장 모으기 (JOI14_stamps) C++17
0 / 100
80 ms 71148 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

const bool typetest = 0;
const int N = 3e3 + 5;
const ll Inf = 1e17;
int n;
ll t, stayleft[N], stayright[N], toleft[N], toright[N];
ll dp[N][N];

void Read()
{
    cin >> n >> t;
    for (int i = 1; i <= n; ++i)
    {
        ll rtop, ptor, ltop, ptol;
        cin >> rtop >> ptor >> ltop >> ptol;
        stayleft[i] = ltop + ptol;
        stayright[i] = rtop + ptor;
        toleft[i] = rtop + ptol;
        toright[i] = ltop + ptor;
    }
}

void Min(ll &x, ll y)
{
    if (x > y)
        x = y;
}

void Solve()
{
    fill_n(&dp[0][0], N * N, Inf);
    dp[1][0] = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 0; j <= n; ++j)
        {
            /// Create a new cycle - Not guarantee that we go throught i-th tramp
            if (j > 0)
                Min(dp[i][j], dp[i][j - 1] + toright[i] - 2 * i * t);
            /// guarantee we go throught i-th tramp
            // End a cycle here
            if (j > 0)
                Min(dp[i + 1][j - 1], dp[i][j] + toleft[i] + 2 * t * t);
            //still go to right
            Min(dp[i + 1][j], dp[i][j] + stayright[i]);
            //go througt a cycle
            Min(dp[i + 1][j + 1], dp[i][j] + toright[i] - 2 * i * t);
            // still go to left (only j > 0)
            if (j > 0)
                Min(dp[i + 1][j], dp[i][j] + stayleft[i]);
        }
    cout << dp[n][0] + (n + 1) * t;
}
 
int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t(1);
    if (typetest)
        cin >> t;
    for (int _ = 1; _ <= t; ++_)
    {
        Read();
        Solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 71020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 71020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 80 ms 71148 KB Output isn't correct
2 Halted 0 ms 0 KB -