답안 #684200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684200 2023-01-20T16:06:30 Z Tigerpants Rack (eJOI19_rack) C++17
100 / 100
5 ms 8148 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 (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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 4 ms 8104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 4 ms 8104 KB Output is correct
6 Correct 4 ms 8148 KB Output is correct
7 Correct 5 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 5 ms 8148 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 4 ms 8104 KB Output is correct
6 Correct 4 ms 8148 KB Output is correct
7 Correct 5 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 5 ms 8148 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 5 ms 8148 KB Output is correct
12 Correct 5 ms 8148 KB Output is correct
13 Correct 4 ms 8148 KB Output is correct
14 Correct 5 ms 8148 KB Output is correct
15 Correct 4 ms 8148 KB Output is correct