Submission #1313988

#TimeUsernameProblemLanguageResultExecution timeMemory
1313988codergCave (IOI13_cave)C++20
100 / 100
119 ms508 KiB
#include "bits/stdc++.h"
#include "cave.h"
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
void setIO(string name = ""){if(name.size()){ freopen((name + ".in").c_str(), "r", stdin);freopen((name + ".out").c_str(), "w", stdout);}}
#define F(i,l,r) for(int i=(l);i<(r);++i)
#define FR(i,l,r) for(int i=(l);i>=(r);--i)
typedef long long ll;

const int maxn=5000;
const int mod=1e9+7;
const int mox=2000*500+505;
const int inf=1e9;

void exploreCave(int N){
    int S[maxn],D[maxn];
    F(i,0,N)S[i]=0;
    vector<int> cand;
    cand.reserve(N);
    F(i,0,N)cand.pb(i);
    F(i,0,N){
        int res=tryCombination(S);
        int target=(res==-1 || res>i)?0:1;
        int l=0,r=cand.size()-1;
        while(l<r){
            int mid=(l+r)>>1;
            if(target==0){
                F(k,mid+1,r+1)S[cand[k]]=1;
            }else{
                F(k,l,mid+1)S[cand[k]]=1;
            }
            res=tryCombination(S);
            if(target==0){
                F(k,mid+1,r+1)S[cand[k]]=0;
            }else{
                F(k,l,mid+1)S[cand[k]]=0;
            }
            bool isopen=(res==-1 || res>i);
            if(isopen)r=mid;
            else l=mid+1;
        }
        int idx=cand[l];
        S[idx]=target;
        D[idx]=i;
        cand[l]=cand.back();
        cand.pop_back();
    }
    answer(S,D);
}

Compilation message (stderr)

cave.cpp: In function 'void setIO(std::string)':
cave.cpp:11:54: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void setIO(string name = ""){if(name.size()){ freopen((name + ".in").c_str(), "r", stdin);freopen((name + ".out").c_str(), "w", stdout);}}
      |                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cave.cpp:11:98: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void setIO(string name = ""){if(name.size()){ freopen((name + ".in").c_str(), "r", stdin);freopen((name + ".out").c_str(), "w", stdout);}}
      |                                                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...