# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
684199 |
2023-01-20T16:04:32 Z |
Tigerpants |
Rack (eJOI19_rack) |
C++17 |
|
2 ms |
468 KB |
#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 (x >= po2.size()) {
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.push_back(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;
}
Compilation message
rack.cpp: In function 'll pow2(ll)':
rack.cpp:20:11: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | if (x >= po2.size()) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |