Submission #906204

# Submission time Handle Problem Language Result Execution time Memory
906204 2024-01-13T15:36:01 Z Marco_Escandon Collecting Stamps 3 (JOI20_ho_t3) C++11
0 / 100
1 ms 348 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<pair<ll,ll>> cad;
ll cost(ll a, ll b)
{
    return abs(cad[a].first-cad[b].first);
}
int main()
{
    ll n,l;
    cin>>n>>l;
    for(int i=0; i<n; i++)
    {
        ll temp;
        cin>>temp;
        cad.push_back({temp,0});
    }
    for(int i=0; i<n; i++)
    {
        ll temp;
        cin>>temp;
        cad[i].second=temp;
        cad.push_back({-(l-cad[i].first),cad[i].second});
    }
    cad.push_back({0,0});
    sort(cad.begin(),cad.end());
    ll p=0;
    for(int i=0; i<cad.size(); i++)
    {
        if(cad[i].first==0)
            p=i;
    }
    vector<vector<vector<vector<ll>>>> dp(2,vector<vector<vector<ll>>>(n+1,vector<vector<ll>>(cad.size()+1,vector<ll>(cad.size()+1,1e15))));
    dp[0][0][p][p]= 0;
    dp[1][0][p][p]= 0;
    ll bs=0;
    for(int k=1; k<=n; k++)
    {
        for(int i=p; i>-1; i--)
        {
            for(int j=p; j<cad.size(); j++)
            {
                dp[0][k][i][j] = min(min(dp[1][k][i+1][j] + cost(i,j),dp[0][k][i+1][j] + cost(i,i+1)),dp[0][k][i][j]);
                dp[1][k][i][j] = min(min(dp[1][k][i][j-1] + cost(j,j-1),dp[0][k][i][j-1] + cost(i,j)),dp[1][k][i][j]);
                if(min(dp[1][k-1][i+1][j] + cost(i,j),dp[0][k-1][i+1][j] + cost(i,i+1))<=cad[i].second)
                {
                    dp[0][k][i][j] = min(min(dp[1][k-1][i+1][j] + cost(i,j),dp[0][k-1][i+1][j] + cost(i,i+1)),dp[0][k][i][j]);
                }
                if(min(dp[1][k-1][i][j-1] + cost(j,j-1),dp[0][k-1][i][j-1] + cost(i,j))<=cad[j].second)
                {
                    dp[1][k][i][j] = min(min(dp[1][k-1][i][j-1] + cost(j,j-1),dp[0][k-1][i][j-1] + cost(i,j)),dp[1][k][i][j]);
                }
                if(dp[0][k][i][j]!=1e15||dp[1][k][i][j]!=1e15) bs=k;
            }
        }
    }
    cout<<bs;
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i=0; i<cad.size(); i++)
      |                  ~^~~~~~~~~~~
ho_t3.cpp:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             for(int j=p; j<cad.size(); j++)
      |                          ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -