# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
433189 | Valaki2 | Rack (eJOI19_rack) | C++14 | 13 ms | 8064 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
void solve() {
ll n, k;
cin >> n >> k;
--k;
vector<ll> powers_of_2_nomodulo(61, 0);
vector<ll> powers_of_2(1 + n, 0);
powers_of_2[0] = 1;
powers_of_2_nomodulo[0] = 1;
for(ll i = 1; i <= n; ++i) {
powers_of_2[i] = (powers_of_2[i - 1] * 2) % mod;
}
for(ll i = 1; i <= 60; ++i) {
powers_of_2_nomodulo[i] = powers_of_2_nomodulo[i - 1] * 2;
}
vector<bool> bits_of_k(1 + n, false);
ll max_bit_of_k = 0;
for(ll i = 0; i <= 60; ++i) {
if(k & powers_of_2_nomodulo[i]) {
bits_of_k[i] = true;
max_bit_of_k = i;
}
}
ll to_add = n - 1;
ll where_we_are = 0;
ll answer = 1;
while(to_add >= 0) {
if(bits_of_k[where_we_are]) {
answer = (answer + powers_of_2[to_add]) % mod;
}
++where_we_are;
--to_add;
}
cout << answer << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |