Submission #684200

#TimeUsernameProblemLanguageResultExecution timeMemory
684200TigerpantsRack (eJOI19_rack)C++17
100 / 100
5 ms8148 KiB
#include <iostream> #include <vector> #include <set> #include <algorithm> #include <map> #include <numeric> #include <iomanip> using namespace std; typedef long long int ll; typedef vector<ll> vll; typedef vector<vll> vvll; const ll mod = 1000000007; vll po2; ll pow2(ll x) { if (po2[x] == -1) { if (x & 1) { po2[x] = (2 * pow2(x - 1)) % mod; } else { po2[x] = (pow2(x / 2) * pow2(x / 2)) % mod; } } return po2[x]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, k; cin >> n >> k; k -= 1; po2.resize(1000002); fill_n(po2.begin(), 1000002, -1); po2[0] = 1; // for a structure with n levels, on which hook should the k'th coat hang // consinder hanging coats one by one. for each rack, it alternates whether it should be hung to the left or right, always starting with the left // so we check the bitrepresentation of k // 0000, 1000, 0100, 1100, 0010, 1010, 0110, 1110, 0001, 1001, 0101, 1101, 0011, 1011, 0111, 1111 // so the answer is k reversed mod 2 ^ n... ll answ = 0; for (int i = 0; i < 63; i++) { if ((k >> i) & 1) { answ += pow2(n - 1 - i); answ %= mod; } } cout << answ + 1 << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...