Submission #999773

# Submission time Handle Problem Language Result Execution time Memory
999773 2024-06-16T06:40:20 Z vjudge1 Rack (eJOI19_rack) C++17
0 / 100
1 ms 348 KB
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define p_b pop_back
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9+7;
ll binpow(ll a, ll b)
{
    ll res = 1;
    while(b)
    {
        if(b & 1)
            res = res * a;
        a *= a;
        b >>= 1;
    }
    return res;
}
ll f(ll l, ll r, ll g)
{
    for(ll j = l+1; j <= r; j++)
        g = 2 * g - 1;
    return g;
}
void solve()
{
    ll n, k, tk;
    cin >> n >> k;
    ll y = log2(k);
    if(binpow(2, y) == k)
    {
        cout << f(y, n, k) << "\n";
    }
    else{
        tk = k;
        vl vect;
        while(k > 2)
        {
            vect.pb(k);
            ll f = log2(k);
            k -= binpow(2, f);
        }
        /*for(auto u : vect)
            cout << u << ' ';
        cout << "\n";*/
        ll lstlvl = 1, lstval = k;
        while(vect.size())
        {
            ll m = log2(vect.back() - k) + 1;
            ll b = f(lstlvl, m, lstval);
            lstlvl = m;
            lstval = b + 1;
            k = vect.back();
            vect.pop_back();
        }
        lstval = f(lstlvl, n, lstval);
        cout << lstval << "\n";
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve();
    }
}

Compilation message

rack.cpp: In function 'void solve()':
rack.cpp:42:14: warning: variable 'tk' set but not used [-Wunused-but-set-variable]
   42 |     ll n, k, tk;
      |              ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -