Submission #472311

# Submission time Handle Problem Language Result Execution time Memory
472311 2021-09-13T11:29:11 Z MamdouhN Cipele (COCI18_cipele) C++17
0 / 90
218 ms 262148 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"

vector<int>R,L,nR;
int required;
int dp[3003][3003];

int solve(int i,int taken)
{
    //cout<<i<<" "<<taken<<endl;
    if(taken ==  0) return 0;
    if(taken - (L.size()-i)>0)return 1e9;
    if(i==L.size())return 1e9;
    if(dp[i][taken]!=-1)return dp[i][taken];
    int ret;
    ret = solve(i+1,taken);
    int idx1 = lower_bound(R.begin(),R.end(),L[i])-R.begin();
    int idx2 = lower_bound(nR.begin(),nR.end(),L[i]*-1)-nR.begin();
    int idx;
    if(idx1==R.size())idx1--;
    if(idx2==nR.size())idx2--;

    if( abs((L[i]*-1) - nR[idx2])  <  abs((L[i]) - R[idx1]) )
        idx = R.size()-idx2-1;
    else
        idx = idx1;
    int  ans=abs(L[i]-R[idx]);
    vector<int>x,y;
    x=R;
    y=nR;
    R.erase(R.begin()+idx);
    nR.erase(nR.begin()+(nR.size()-idx-1));
    ret = min(ret,max(ans,solve(i+1,taken-1)));
    R=x;
    nR=y;
    return dp[i][taken] = ret;
}


main()
{
    memset(dp,-1,sizeof dp);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        L.push_back(x);
    }
    for(int i=0;i<m;i++)
    {
        int x;
        cin>>x;
        R.push_back(x);
    }

    if(n>m)
    {
        swap(m,n);
        swap(L,R);
    }
    required =  n;
    for(int i=0;i<R.size();i++)nR.push_back(R[i]*-1);
    sort(L.begin(),L.end());
    sort(R.begin(),R.end());
    sort(nR.begin(),nR.end());

    int ans = 0;

    cout<<solve(0,required)<<endl;
}

Compilation message

cipele.cpp: In function 'long long int solve(long long int, long long int)':
cipele.cpp:15:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     if(i==L.size())return 1e9;
      |        ~^~~~~~~~~~
cipele.cpp:22:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     if(idx1==R.size())idx1--;
      |        ~~~~^~~~~~~~~~
cipele.cpp:23:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     if(idx2==nR.size())idx2--;
      |        ~~~~^~~~~~~~~~~
cipele.cpp: At global scope:
cipele.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   42 | main()
      | ^~~~
cipele.cpp: In function 'int main()':
cipele.cpp:66:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for(int i=0;i<R.size();i++)nR.push_back(R[i]*-1);
      |                 ~^~~~~~~~~
cipele.cpp:71:9: warning: unused variable 'ans' [-Wunused-variable]
   71 |     int ans = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Runtime error 197 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 218 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 120388 KB Output is correct
2 Incorrect 146 ms 236180 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 78676 KB Output is correct
2 Incorrect 147 ms 236100 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 141 ms 236048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 141 ms 235944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 144 ms 236072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 203 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 207 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 193 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -