Submission #427053

#TimeUsernameProblemLanguageResultExecution timeMemory
427053oscar1fWiring (IOI17_wiring)C++17
0 / 100
947 ms292 KiB
#include<bits/stdc++.h> /*#include <cassert> #include <cstdio>*/ #include "wiring.h" using namespace std; const long long MILLE=1000; const long long INFINI=MILLE*MILLE*MILLE*MILLE*MILLE*MILLE,ZERO=0; const int MAX_NB=100*1000,MAX_DIFF=15; int nbRouge,nbBleu; long long dyna[MAX_NB][MAX_DIFF]; int rouge[MAX_NB],bleu[MAX_NB]; long long calc_min(int posRouge,int posBleu) { if (posRouge==nbRouge and posBleu==nbBleu) { return ZERO; } if (posRouge>=nbRouge or posBleu>=nbBleu or abs(posRouge-posBleu)>7) { return INFINI; } if (dyna[posRouge][posRouge-posBleu+7]!=ZERO) { return dyna[posRouge][posRouge-posBleu+7]; } long long val=INFINI; val=min(val,calc_min(posRouge+1,posBleu+1)); val=min(val,calc_min(posRouge,posBleu+1)); val=min(val,calc_min(posRouge+1,posBleu)); val+=(long long)abs((long long)rouge[posRouge]-(long long)bleu[posBleu]); dyna[posRouge][posBleu]=val; return val; } long long min_total_length(vector<int> r, vector<int> b) { nbRouge=r.size(); nbBleu=b.size(); for (int i=0;i<nbRouge;i++) { rouge[i]=r[i]; } for (int i=0;i<nbBleu;i++) { bleu[i]=b[i]; } return calc_min(0,0); } /* int main() { int n, m; assert(2 == scanf("%d %d", &n, &m)); vector<int> r(n), b(m); for(int i = 0; i < n; i++) assert(1 == scanf("%d", &r[i])); for(int i = 0; i < m; i++) assert(1 == scanf("%d", &b[i])); long long res = min_total_length(r, b); printf("%lld\n", res); return 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...