This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// https://oj.uz/problem/view/eJOI19_rack
// European Junior Olympiad in Informatics 2019
// Day 1 Tasks
// Hanging Rack
#include <bitset>
#include <iostream>
std::bitset<10000000> tab;
size_t convert_to_bin(long long n) {
if (n == 0) {
return 0;
}
long long i = 0;
while (n > 0) {
tab[i] = n % 2;
n = n / 2;
i++;
}
return i - 1;
}
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
long long n, k;
std::cin >> n >> k;
k--;
convert_to_bin(k);
long long rack = 1;
for (int i = 0; i < n; i++) {
long long temp = tab[i] ? (1ll << (n - i - 1)) : tab[i];
rack += temp;
// std::cout << tab[i] << " | val: " << temp << '\n';
}
// std::cout << '\n';
std::cout << rack << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |