This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "wiring.h"
using namespace std;
using ll=long long;
const ll TAILLE_MAX=100*1000+5,INFINI=(ll)1000*1000*1000*1000*1000;
ll nbRouge,nbBleu;
vector<ll> posBleu,posRouge;
unordered_map<ll,ll> memo;
ll dyna(ll idRouge,ll idBleu) {
if (idRouge==nbRouge and idBleu==nbBleu) {
return 0;
}
if (idRouge==nbRouge or idBleu==nbBleu) {
return INFINI;
}
ll caseTab=idRouge*TAILLE_MAX+idBleu;
ll ans=memo[caseTab];
if (ans!=0) {
return ans;
}
ans=abs(posRouge[idRouge]-posBleu[idBleu])+min(min(dyna(idRouge,idBleu+1),dyna(idRouge+1,idBleu)),dyna(idRouge+1,idBleu+1));
memo[caseTab]=ans;
//cout<<idRouge<<" "<<idBleu<<" : "<<ans<<endl;
return ans;
}
ll min_total_length(vector<int> r,vector<int> b) {
nbRouge=r.size();
nbBleu=b.size();
for (auto i:r) {
posRouge.push_back(i);
}
for (auto i:b) {
posBleu.push_back(i);
}
return dyna(0,0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |