Submission #150992

#TimeUsernameProblemLanguageResultExecution timeMemory
150992mohammedehab2002Wine Tasting (FXCUP4_wine)C++17
57 / 100
10 ms1024 KiB
#include "bartender.h" #include <bits/stdc++.h> using namespace std; vector<int> BlendWines(int k,vector<int> r) { int n=r.size(),b=(n+2)/3; vector<int> ans; for (int i=0;i<n;i++) ans.push_back((r[i]-1)%b+1); return ans; }
#include "taster.h" #include <bits/stdc++.h> using namespace std; vector<int> d[3]; bool cmp(int a,int b) { return Compare(a,b)==-1; } void go(int l,int r,vector<pair<int,int> > &tmp,int j) { if (l==r) { d[tmp[l].second].push_back(j); tmp.erase(tmp.begin()+l); } else { int mid=(l+r+1)/2; if (Compare(tmp[mid].first,j)==-1) go(mid,r,tmp,j); else go(l,mid-1,tmp,j); } } vector<int> SortWines(int k,vector<int> a) { int n=a.size(); vector<int> v,r(n); for (int i=0;i<n;i++) { if (a[i]==1) v.push_back(i); } if (v.size()<3) { sort(v.begin(),v.end(),cmp); for (int i=0;i<n;i++) r[v[i]]=i+1; return r; } if (Compare(v[0],v[1])==1) swap(v[0],v[1]); if (Compare(v[0],v[2])==1) swap(v[0],v[2]); if (Compare(v[1],v[2])==1) swap(v[1],v[2]); for (int i=0;i<3;i++) d[i].push_back(v[i]); for (int i=2;i<=n;i++) { vector<pair<int,int> > tmp; for (int j=0;j<3;j++) tmp.push_back({v[j],j}); for (int j=0;j<n;j++) { if (a[j]==i) go(0,(int)tmp.size()-1,tmp,j); } } vector<int> ans; for (int i=0;i<3;i++) { for (int j:d[i]) ans.push_back(j); } for (int i=0;i<n;i++) r[ans[i]]=i+1; return r; }
#Verdict Execution timeMemoryGrader output
Fetching results...