Submission #312508

#TimeUsernameProblemLanguageResultExecution timeMemory
312508monus1042Cipele (COCI18_cipele)C++17
63 / 90
233 ms200884 KiB
// NK #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<ll> vll; #define eb emplace_back #define pb push_back #define pob pop_back #define psf push_front #define pof pop_front #define mkp make_pair #define all(x) x.begin(), x.end() #define Bolivia_is_nice ios::sync_with_stdio(false), cin.tie(nullptr) /* 3 5 5 5 7 8 8 9 3 5 5 7 8 brute force? dp? it is ok that it is sorted, so only matches are important f(int pos, int pos2){ make it match -> ans1 = max( abs(pos - pos2), then f(pos-1, pos2-1) ) don't match -> ans2 = f(pos-1, pos2) return min(ans1, ans2) } */ vi a,b; const int MAXS = 5005; int dp[MAXS][MAXS]; int f(int posa, int posb){ if (posa == -1) return 0; if (dp[posa][posb] != -1) return dp[posa][posb]; int ans1, ans2; ans1 = ans2 = 2e9; if (posa < posb){ ans1 = max( abs(a[posa] - b[posb]), f(posa-1, posb-1) ); ans2 = f(posa, posb-1); }else{ ans1 = max( abs(a[posa] - b[posb]), f(posa-1, posb-1) ); } return dp[posa][posb] = min(ans1, ans2); } void solve(){ int n,m; cin>>n>>m; for (int i=0; i<n; ++i){ int x; cin>>x; a.pb(x); } for (int i=0; i<m; ++i){ int x; cin>>x; b.pb(x); } sort(all(a)), sort(all(b)); if (a.size() > b.size()) swap(a,b); if (a.size() == b.size()){ int curr = 0; for (int j=0; j<a.size(); ++j) curr = max(curr, abs(a[j] - b[j])); cout<<curr<<'\n'; return; } memset(dp, -1, sizeof dp); cout<<f(a.size()-1, b.size()-1)<<'\n'; } int main(){ Bolivia_is_nice; int t = 1; //cin>>t; while(t--) solve(); return 0; } /* ~/.emacs */

Compilation message (stderr)

cipele.cpp: In function 'void solve()':
cipele.cpp:68:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for (int j=0; j<a.size(); ++j) curr = max(curr, abs(a[j] - b[j]));
      |                   ~^~~~~~~~~
#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...