답안 #906059

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
906059 2024-01-13T13:01:21 Z mannshah1211 A Plus B (IOI23_aplusb) C++17
10 / 100
1 ms 348 KB
#include "aplusb.h"
#include <bits/stdc++.h>
 
#pragma GCC optimize("O3,unroll-loops")
 
std::vector<int> smallest_sums(int n, std::vector<int> a, std::vector<int> b) {
	std::function<int(int)> count_smaller = [&](int sum) {
		int cnt = 0;
		int ptr = 0;
		for (int i = 0; i < n; i++) {
			while (a[i] + b[ptr] <= sum && ptr < n) {
				++ptr;
			}
			cnt += ptr;
			if (cnt >= n + 1) {
				return cnt;
			}
		}
		return cnt;
	};
	int low = 0, high = 2E9, index = -1;
	while (low <= high) {
		int middle = low + ((high - low) / 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 - low) / 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 1 ms 344 KB 1st lines differ - on the 2nd token, expected: '3', found: '1'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 1 ms 344 KB 1st lines differ - on the 2nd token, expected: '3', found: '1'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 1 ms 344 KB 1st lines differ - on the 2nd token, expected: '3', found: '1'
6 Halted 0 ms 0 KB -