1 solutions

  • 0
    @ 2025-11-5 18:22:47

    C++ :

    #include <iostream>
    using namespace std;
    #include <cstdio>
    #include <cstring>
    
    bool tree[2097152];
    int last,sd;
    int d,I;
    
    void work(int x)
    {
    	sd++;
    	if (tree[x])
    	{
    		tree[x]=false;
    		if (sd==d)
    		{
    			last=x;
    			return;
    		}
    		work(x*2+1);
    	}
    	else
    	{
    		tree[x]=true;
    		if (sd==d)
    		{
    			last=x;
    			return;
    		}
    		work(x*2);
    	}
    }
    
    int main()
    {
    	memset(tree,false,sizeof(tree));
    	cin>>d>>I;
    	for (int i=1; i<=I; i++) 
    	{
    		sd=0;
    	    work(1);
    	}
    	cout<<last;
    }
    
    
    
    
    • 1

    Information

    ID
    18864
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By