Блог пользователя Adityaxv

Автор Adityaxv, 6 недель назад, По-английски

1846C - Rudolf and the Another Competition

My Code

I don't know why my code is not working even though the approach is correct, and I don't see anything wrong with my code. Even the 10th test case where it failed should give the right answer, according to me. I would be grateful if you could find out where the error is.

  • Проголосовать: нравится
  • -26
  • Проголосовать: не нравится

»
6 недель назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

yeah i found your problem.

The problem is how you find the rudolf result, you put rudolf the id 0, but in the sort function you not drive the case where the amount of problems and the penalizing are the same.

For example imagine there is two competidor, they have 1 1 0, and 1 1 1, so at the moment to sort there are two possibles case: {[1 1 0], [1 1 1]} or {[1 1 1], [1 1 0]}. And in the stament say you have to get the first if there is and draw.

.

  • The solution

You can compare by problems and pen for found the score of rudolf, or put another case (the id) in the lambda sort when the problems and the penalize are equal

if (get<0>(a) == get<0>(b) && get<1>(a) == get<1>(b)){
         return get<2>(a) < get<2> (b);
}
  • »
    »
    6 недель назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Thanks for replying! Your solution worked.

    If we sort vector<pair<int, int>> pr using the default std::sort function, it automatically sorts the pr.second value in non-decreasing order if the pr.first values are equal.

    So, I always thought that we don't need to specify the sort function if we want their value sorted in non-decreasing order if the previous values are equal.

    But guess it is not true for more than two values! I even implemented your approach before, but I made mistakes in implementing that :(

    • »
      »
      »
      6 недель назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      i'm not sure, but when you used a personalized comp, you replace the default like you said, so if you will use a lambda sort, remember that you are doing is replace the default comparator to your new fuction, so be sure in thinking in all cases...

      (please correct me if i'm wrong)

      • »
        »
        »
        »
        6 недель назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        I checked with vector<pair<int, int>>. You are right! We have modified the sort function so it won't sort automatically the non-specified value in a non-decreasing order.