Submission #3747209


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

int64_t Len[51], Pat[51];

int64_t rec(int64_t k, int64_t x){
    // バーガー全部なら前計算の結果を返す
    if(x == Len[k]) return Pat[k];
    
    int64_t ans = 0;

    // 下のバン
    x--;

    // 下のk-1バーガー
    if(x > 0){
        int64_t l = min(x, Len[k-1]);
        ans += rec(k-1, l);
        x -= l;
    }

    // 真ん中のパティ
    if(x > 0){
        ans++;
        x--;
    }

    // 上のk-1バーガー
    if(x > 0){
        int64_t l = min(x, Len[k-1]);
        ans += rec(k-1, l);
        x -= l;
    }

    return ans;
}

int main(){
    int64_t N, X;
    cin >> N >> X;
    
    Len[0] = Pat[0] = 1;
    for(int i=1; i<=N; i++){
        Len[i] = Len[i-1] * 2 + 3;
        Pat[i] = Pat[i-1] * 2 + 1;
    }

    cout << rec(N, X) << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Christmas
User betrue12
Language C++14 (GCC 5.4.1)
Score 400
Code Size 904 Byte
Status
Exec Time 1 ms
Memory 256 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 a01, a02, a03
All 400 / 400 a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16
Case Name Status Exec Time Memory
a01 1 ms 256 KB
a02 1 ms 256 KB
a03 1 ms 256 KB
b04 1 ms 256 KB
b05 1 ms 256 KB
b06 1 ms 256 KB
b07 1 ms 256 KB
b08 1 ms 256 KB
b09 1 ms 256 KB
b10 1 ms 256 KB
b11 1 ms 256 KB
b12 1 ms 256 KB
b13 1 ms 256 KB
b14 1 ms 256 KB
b15 1 ms 256 KB
b16 1 ms 256 KB