Submission #472311

#TimeUsernameProblemLanguageResultExecution timeMemory
472311MamdouhNCipele (COCI18_cipele)C++17
0 / 90
218 ms262148 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...