답안 #999775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999775 2024-06-16T06:44:42 Z vjudge1 Rack (eJOI19_rack) C++17
0 / 100
0 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 && binpow(2, log2(k)) != k)
        {
            vect.pb(k);
            ll f = log2(k);
            k -= binpow(2, f);
        }
        /*for(auto u : vect)
            cout << u << ' ';
        cout << "\n";*/
        ll lstlvl = log2(k), 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;
      |              ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -