| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 466732 | mtxas | Rack (eJOI19_rack) | C++14 | 15 ms | 1316 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>
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
#define pll pair<ll, ll>
#define mii map<int, int>
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(x) ((int)x.size())
#define turbo() cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false)
#define _fre() freopen("input.txt", "r", stdin)
#define _for(a, b, c) for(int (a) = (b); (a) < (c); (a)++)
#define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
#define _forneq(a, b, c) for(int (a) = (b); (a) >= (c); (a)--)
#define _forn(a, b, c) for(int (a) = (b); (a) > (c); (a)--)
using namespace std;
/**********************************************************************************
                                STRUCTS
**********************************************************************************/
/**********************************************************************************
                               VARIABLES
**********************************************************************************/
const int mod = 1e9+7;
/**********************************************************************************
                               FUNCTIONS
**********************************************************************************/
/**********************************************************************************
                                 MAIN
**********************************************************************************/
int main(){
    //_fre();
    //freopen("input.txt", "w", stdout);
    turbo();
    ll n, k; cin>>n>>k;
    stack<char> stek;
    int pow = 0;
    ll g = 1;
    _for(i, 0, n) {
        g*= 2, pow++;
        if(g > k) break;
    }
    _for(i, 0, n-pow) stek.push('L');
    _forneq(h, pow, 1){
        ll mid = g/2;
        if(k > mid) k-= mid, stek.push('R');
        else stek.push('L');
        g/= 2;
    }
    ll v = 1;
    while(!stek.empty()){
        char c= stek.top(); stek.pop();
        if(c == 'L')    v = 2LL*v;
        else if(c=='R') v = 2LL*v+1;
        v%= mod;
    }
    g = 1; _for(i, 0, n) g*= 2LL, g%= mod;
    cout<<(mod+v-g+1)%mod;
}
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... | ||||
