Файл
image_2024-07-15_22-59-00.png · 8 КБ · натисніть — покажемо
image_2024-07-15_22-59-00.png · 8 КБ · натисніть — покажемо
nimaga bu memory limit olyapti?
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <algorithm>
std::string binstr(int num) {
std::string bin = std::bitset<32>(num).to_string();
const auto pos = bin.find_first_not_of('0');
if (pos != std::string::npos) {
return bin.substr(pos);
}
return "0";
}
int foo(int a, int b) {
std::vector<std::string> x;
std::string y = "";
int d = 0;
for (int i = a; i <= b; ++i) {
std::string s = binstr(i);
x.push_back(s);
y += s;
int ones = std::count(y.begin(), y.end(), '1');
int zeros = y.size() - ones;
if (y.size() % 2 == 0 && ones == zeros) {
d += 1;
} else {
y = "";
}
}
return d;
}
int main() {
int a, b;
std::cin >> a >> b;
std::cout << foo(a, b) << std::endl;
return 0;
}
https://robocontest.uz/tasks/1211