Submission #675665

#TimeUsernameProblemLanguageResultExecution timeMemory
675665a_aguiloRack (eJOI19_rack)C++14
100 / 100
1 ms212 KiB
#include<bits/stdc++.h> using namespace std; unordered_map<long long, long long> powers; const int MOD = 1e9+7; long long int PowerTwo(long long int exponent){ if(powers.find(exponent) != powers.end()) return powers[exponent]; long long semiAns = PowerTwo(exponent/2); long long ans = (semiAns*semiAns)%MOD; if(exponent%2) { ans*= 2; ans%=MOD; } return powers[exponent] = ans; } long long getPos(long long int n, long long int k){ if(k == 1) return 1; if(k%2){ return getPos(n-1, k/2 +1); } else{ long long semiAns = PowerTwo(n-1); long long ans = (semiAns + getPos(n-1, k/2))%MOD; return ans; } } int main(){ powers[0] = 1; powers[1] = 2; powers[2] = 4; long long int n, k; cin >> n >> k; cout << getPos(n, k)<< endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...