답안 #900642

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900642 2024-01-08T19:00:47 Z mannshah1211 A Plus B (IOI23_aplusb) C++17
컴파일 오류
0 ms 0 KB
#include "aplusb.h"
#include <bits/stdc++.h>

std::vector<int> smallest_sums(int n, std::vector<int> a, std::vector<int> b) {
	int n = a.size();
	std::function<int(int)> count_smaller = [&](int sum) {
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			int low = 0, high = n - 1, index = -1;
			while (low <= high) {
				int middle = (low + high) / 2;
				if (a[i] + b[middle] <= sum) {
					index = middle;
					low = middle + 1;
				} else {
					high = middle - 1;
				}
			}
			cnt += (index + 1);
		}
		return cnt;
	};
	int low = 0, high = 2E9, index = -1;
	while (low <= high) {
		int middle = (low + high) / 2;
		if (count_smaller(middle) >= n) {
			index = middle;
			high = middle - 1;
		} else {
			low = middle + 1;
		}
	}
	std::vector<int> answer;
	int taken = 0;
	for (int i = 0; i < n; i++) {
		int low = 0, high = n - 1, ind = -1;
		while (low <= high) {
			int middle = (low + high) / 2;
			if (a[i] + b[middle] < index) {
				ind = middle;
				low = middle + 1;
			} else {
				high = middle - 1;
			}
		}
		for (int j = 0; j <= ind; j++) {
			answer.push_back(a[i] + b[j]);
		}
		taken += (ind + 1);
	}
	for (int j = 0; j < n - taken; j++) {
		answer.push_back(index);
	}
	std::sort(answer.begin(), answer.end());
	return answer;
}

Compilation message

aplusb.cpp: In function 'std::vector<int> smallest_sums(int, std::vector<int>, std::vector<int>)':
aplusb.cpp:5:6: error: declaration of 'int n' shadows a parameter
    5 |  int n = a.size();
      |      ^
aplusb.cpp:4:36: note: 'int n' previously declared here
    4 | std::vector<int> smallest_sums(int n, std::vector<int> a, std::vector<int> b) {
      |                                ~~~~^