제출 #991940

#제출 시각아이디문제언어결과실행 시간메모리
991940jakobrsA Plus B (IOI23_aplusb)C++17
10 / 100
1 ms348 KiB
#include "aplusb.h"

#include <queue>
#include <set>
#include <vector>

std::vector<int> smallest_sums(int N, std::vector<int> A, std::vector<int> B) {
  auto cmp = [&](std::pair<int, int> a, std::pair<int, int> b) {
    auto [a1, a2] = a;
    auto [b1, b2] = b;

    return A[a1] + B[a2] > A[b1] + B[b2];
  };
  auto pq =
      std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>,
                          decltype(cmp)>(cmp);
  pq.push({0, 0});

  auto seen = std::set<std::pair<int, int>>{};

  std::vector<int> results;
  for (int i = 0; i < N; i++) {
    auto [a, b] = pq.top();
    pq.pop();
    if (seen.find({a, b}) != seen.end())
      continue;
    seen.insert({a, b});
    results.push_back(A[a] + B[b]);
    if (a + 1 < A.size())
      pq.push({a + 1, b});
    if (b + 1 < B.size())
      pq.push({a, b + 1});
  }

  return results;
}

컴파일 시 표준 에러 (stderr) 메시지

aplusb.cpp: In function 'std::vector<int> smallest_sums(int, std::vector<int>, std::vector<int>)':
aplusb.cpp:29:15: warning: comparison of integer expressions of different signedness: 'std::tuple_element<0, std::pair<int, int> >::type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     if (a + 1 < A.size())
      |         ~~~~~~^~~~~~~~~~
aplusb.cpp:31:15: warning: comparison of integer expressions of different signedness: 'std::tuple_element<1, std::pair<int, int> >::type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     if (b + 1 < B.size())
      |         ~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...