Submission #270216

# Submission time Handle Problem Language Result Execution time Memory
270216 2020-08-17T13:12:44 Z JuliusMieliauskas Rack (eJOI19_rack) C++14
100 / 100
13 ms 2488 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vll vector<long long>
#define MOD 1000000007
#define endl '\n'

typedef long long ll;

void print(vi v){
    cout<<"Contents of vector:\n";
    for(auto x : v) cout<<x<<" ";
    cout<<endl<<endl;
}

ll stringToLL(string s){
    ll dec_value = 0ll;

    ll base = 1ll;

    for (int i = s.length() - 1; i >= 0; i--) {
        if (s[i] == '1') dec_value += base%MOD;
        base = (base * 2ll)%MOD;
        dec_value = dec_value%MOD;
    }
    return dec_value%MOD;
}

void solve(){
    ll n, k; cin>>n>>k;

    string s = "";
    k--;
    for(int i = 0; i<n; i++){
        if((1ll<<i) > k) {
            for(int j = i; j<n; j++) s += '0';
            break;
        }
        if (k & (1ll<<i)) {
            s += '1';
        } else {
            s += '0';
        }
    }
    //reverse(all(s));
    //cout<<"S: "<<s<<endl;
    ll ans = stringToLL(s)%MOD;

    cout<<(ans+1)%MOD<<endl;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    //ifstream cin("input.txt"); ofstream cout("output.txt");///cia failai

    //int T; cin>>T;
    int T = 1;

    for(int it = 1; it<=T; it++){
        solve();

    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 13 ms 2488 KB Output is correct