Submission #558060

#TimeUsernameProblemLanguageResultExecution timeMemory
558060groshiCave (IOI13_cave)C++17
100 / 100
939 ms660 KiB
#include<iostream>
#include<vector>
#include "cave.h"
using namespace std;
bool nwm[5010];
int s1[5010],d1[5010];///s to w ktora strone dobry pstryczek, d1 to ktore drzwi otwiera
/*int tryCombination(vector<int> Q)
{
    for(int i=0;i<Q.size();i++)
        cout<<Q[i]<<" ";
    int x;
    cin>>x;
    return x;
}*/
void exploreCave(int n)
{
    for(int i=0;i<n;i++)
    {
        int chce[n+3];
        for(int j=0;j<n;j++)
        {
            if(nwm[j]==0)
                chce[j]=0;
            else chce[j]=s1[j];
        }
        //cout<<"wstepnie ";
        int k=tryCombination(chce);
        int on;
        if(k!=i)///to znaczy ze s1[i]=0;
            on=0;
        else on=1;
        //cout<<"drzwi "<<i<<" maja "<<on<<"\n";
        int pocz=0,kon=n,sre,ostd;
        while(pocz<kon)
        {
            //cout<<"sprawdzam przedzial "<<pocz<<" "<<kon<<"\n";
            sre=(pocz+kon)/2;
            for(int j=0;j<n;j++)
            {
                if(nwm[j]==1)
                    chce[j]=s1[j];
                else{
                    if(j<pocz || j>sre)
                        chce[j]=on;
                    else chce[j]=!on;
                }
            }
            int k=tryCombination(chce);
            if(k==i)
            {
                //cout<<"w przedziale\n";
                kon=sre;
                ostd=sre;
            }
            else {
                    //cout<<"poza przedzialem\n";
                    pocz=sre+1;
            }
        }
        s1[ostd]=on;
        d1[ostd]=i;
        nwm[ostd]=1;
    }
    answer(s1,d1);
    /*for(int i=0;i<n;i++)
        cout<<s1[i]<<" ";
    cout<<"\n";
    for(int i=0;i<n;i++)
        cout<<d1[i]<<" ";*/
}

Compilation message (stderr)

cave.cpp: In function 'void exploreCave(int)':
cave.cpp:62:18: warning: 'ostd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |         nwm[ostd]=1;
      |         ~~~~~~~~~^~
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...