답안 #201031

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201031 2020-02-09T06:36:11 Z HellAngel Just Long Neckties (JOI20_ho_t1) C++14
0 / 100
47 ms 69752 KB
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int maxn = 207;

int dp[maxn][maxn][maxn][2], x[maxn], t[maxn], n, l, sum, ans;

/// left, right, cnt, curpos

int Dist(int i, int j)
{
    return min(abs(i - j), min(i, l - i) + min(j, l - j));
}

void Minimize(int &a, int b, bool check)
{
    if(check)
    a = min(a, b);
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
    cin >> n >> l;
    fill_n(&dp[0][0][0][0], maxn * maxn * maxn * 2, inf);
    for(int i = 1; i <= n; i++) cin >> x[i];
    for(int i = 1; i <= n; i++) cin >> t[i];
    dp[0][0][0][0] = dp[0][0][0][1] = 0;
    for(int len = 1; len <= n; len++)
    {
        for(int r = 0; r <= len; r++)
        {
            int l = len - r;
            for(int cnt = 0; cnt <= len; cnt++)
            {
                if(cnt < len)
                {
                    if(l > 0)
                    {
                        Minimize(dp[l][r][cnt][0], dp[l - 1][r][cnt][0] + Dist(x[l], x[l - 1]), 1);
                        Minimize(dp[l][r][cnt][0], dp[l - 1][r][cnt][1] + Dist(x[n - r + 1], x[l]), 1);
                    }
                    if(r > 0)
                    {
                        Minimize(dp[l][r][cnt][1], dp[l][r - 1][cnt][0] + Dist(x[l], x[n - r + 1]), 1);
                        Minimize(dp[l][r][cnt][1], dp[l][r - 1][cnt][1] + Dist(x[n - r + 2], x[n - r + 1]), 1);
                    }
                }
                if(cnt > 0)
                {
                    if(l > 0)
                    {
                        int val;
                        val = dp[l - 1][r][cnt - 1][0] + Dist(x[l], x[l - 1]);
                        Minimize(dp[l][r][cnt][0], val, val <= t[l]);
                        val = dp[l - 1][r][cnt - 1][1] + Dist(x[n - r + 1], x[l]);
                        Minimize(dp[l][r][cnt][0], val, val <= t[l]);
                    }
                    if(r > 0)
                    {
                        int val;
                        val = dp[l][r - 1][cnt - 1][0] + Dist(x[l], x[n - r + 1]);
                        Minimize(dp[l][r][cnt][1], val, val <= t[n - r + 1]);
                        val = dp[l][r - 1][cnt - 1][1] + Dist(x[n - r + 2], x[n - r + 1]);
                        Minimize(dp[l][r][cnt][1], val, val <= t[n - r + 1]);
                    }
                }
                if(dp[l][r][cnt][0] != inf) 
                {
                    ans = max(ans, cnt);
                }
                if(dp[l][r][cnt][1] != inf) ans = max(ans, cnt);
            }
        }
    }
    cout << ans;
}

Compilation message

ho_t1.cpp: In function 'int32_t main()':
ho_t1.cpp:25:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 69752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 69752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 69752 KB Output isn't correct
2 Halted 0 ms 0 KB -