Submission #149375

# Submission time Handle Problem Language Result Execution time Memory
149375 2019-09-01T06:21:14 Z Powered By Zigui(#3580, aaaa, evenharder, best_sheild97) Wine Tasting (FXCUP4_wine) C++17
0 / 100
10 ms 804 KB
#include "bartender.h"

using namespace std;

std::vector<int> BlendWines(int K, std::vector<int> R){
    int x[30] = {1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,8,9,10,11,12};
    vector<int> A(R.size());
    int n = R.size();
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(x[j] == i+1)
            {
                A[j] = x[i];
            }
        }
    }
	return A;
}
#include "taster.h"

#include <vector>
#include <algorithm>
using namespace std;
std::vector<int> v[31];
void SortSomeWines(std::vector<int>& p)
{
    if(p.size() <= 1) return;
    else if(p.size() == 2)
    {
        if(Compare(p[0], p[1]) == 1) swap(p[0], p[1]);
    }
    else if(p.size() == 3)
    {
        int a = p[0], b = p[1], c = p[2];
        if(Compare(a, b) == 1)
        {
            swap(a, b);
        }
        if(Compare(c, a) == 1)
        {
            if(Compare(b, c) == 1)
            {
                swap(b, c);
            }
            p = vector<int>({a, b, c});
        }
        else
        {
            p = vector<int>({c, a, b});
        }
    }
    else
    {
        int l1, l2, h1, h2, ll, hh, m1, m2;
        if(Compare(p[0], p[1]) == -1) 
            h1 = p[0], l1 = p[1];
        else h1 = p[1], l1 = p[0];
        if(Compare(p[2], p[3]) == -1) 
            h2 = p[2], l2 = p[3];
        else h2 = p[2], l2 = p[2];
        
        if(Compare(l1, l2) == 1)
            ll = l1, m1 = l2;
        else ll = l2, m1 = l1;
        if(Compare(h1, h2) == -1)
            hh = h1, m2 = h2;
        else hh = h2, m2 = h1;
        if(Compare(m1, m2) == 1)
            p = vector<int>({hh, m2, m1, ll});
        else p = vector<int>({hh, m1, m2, ll});
    }
}
std::vector<int> SortWines(int K, std::vector<int> A) {
	int N = A.size();

    for(int i=0;i<A.size();i++)
    {
        v[A[i]].push_back(i);
    }

    for(int i=1;i<=30;i++)
    {
        SortSomeWines(v[i]);
    }
    vector<int> ans, rans(A.size());
    for(int i=1;i<=30;i++)
    {
        for(int x : v[i])
        {
            ans.push_back(x);
        }
    }
    for(int i=0;i<A.size();i++)
    {    
        rans[ans[i]] = i+1;
    }
	return rans;
}

Compilation message

taster.cpp: In function 'std::vector<int> SortWines(int, std::vector<int>)':
taster.cpp:58:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<A.size();i++)
                 ~^~~~~~~~~
taster.cpp:75:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<A.size();i++)
                 ~^~~~~~~~~
taster.cpp:56:6: warning: unused variable 'N' [-Wunused-variable]
  int N = A.size();
      ^
# Verdict Execution time Memory Grader output
1 Correct 9 ms 644 KB Correct
2 Correct 10 ms 644 KB Correct
3 Incorrect 10 ms 804 KB Wrong
4 Halted 0 ms 0 KB -