답안 #656146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
656146 2022-11-06T11:32:19 Z borisAngelov Rack (eJOI19_rack) C++17
100 / 100
1 ms 424 KB
#include <iostream>
#include <vector>

using namespace std;

const long long mod = 1000000007;

long long fastPow(long long a, long long b) {
    if (b == 0) return 1LL;

    if (b % 2 == 0) {
        long long result = fastPow(a, b / 2);
        return (result * result) % mod;
    }

    return (a * fastPow(a, b - 1)) % mod;
}

int main() {
    int n; cin >> n;
    long long k; cin >> k;

    vector<bool> digits(n, false);

    int idx = n;
    k--;

    while (k != 0) {
        digits[--idx] = k % 2;
        k = k / 2;
    }

    long long ans = 0;

    for (int i = 0; i < n; i++) {
        if (digits[i] == 1) {
            ans += fastPow(2, i);

            if (ans >= mod) ans -= mod;
        }
    }

    ans++;
    ans %= mod;

    cout << ans << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 0 ms 296 KB Output is correct
15 Correct 1 ms 424 KB Output is correct