Submission #439176

# Submission time Handle Problem Language Result Execution time Memory
439176 2021-06-29T11:06:24 Z elazarkoren Rack (eJOI19_rack) C++17
100 / 100
218 ms 296 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

struct Tree{
    int val = 0, l, r;
    Tree *lp, *rp;
    Tree(int l, int r): l(l), r(r) {
        if (l + 1 != r) {
            lp = new Tree(l, (l + r) / 2);
            rp = new Tree((l + r) / 2, r);
        }
    }
    int query() {
        if (l + 1 == r) {
//            if (val) return -1;
            val = 1;
            return l;
        }
        val++;
        if (lp->val == rp->val) return lp->query();
        return rp->query();
    }
};

const int mod = 1e9 + 7;

ll Power(ll a, int b) {
    if (!b) return 1;
    return Power(a * a % mod, b / 2) * (b & 1 ? a : 1) % mod;
}

ll Invert(ll a) {
    return Power(a, mod - 2);
}

int n;

int Solve(int i, ll l, ll r, ll w) {
    if (i == n) {
        return l;
    }
    ll right = w / 2;
    ll left = w - right;
    if (left > right) {
        return Solve(i + 1, l, (l + r) * Invert(2) % mod, left);
    }
    return Solve(i + 1, (l + r) * Invert(2) % mod, r, right);
}

int main() {
    ll k;
    cin >> n >> k;
    cout << Solve(0, 1, (Power(2, n) + 1) % mod, k);
//    Tree t(1, (1 << n) + 1);
//    for (int i = 0; i < k - 1; i++){
//        t.query();
//    }
//    cout << t.query();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 14 ms 204 KB Output is correct
15 Correct 218 ms 272 KB Output is correct