Submission #308770

#TimeUsernameProblemLanguageResultExecution timeMemory
308770chubyxdxdCounting Mushrooms (IOI20_mushrooms)C++17
0 / 100
1 ms256 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
int count_mushrooms(int n){
	vector<int> A;
	vector<int> B;
	A.pb(0);
	int j;
	for(int i=1;i<n;i++){
	  if(A.size()>=2 or B.size()>=2)break;
	  vector<int> m;
	  m.pb(0);
	  m.pb(i);
	  int f=use_machine(m);
	  j=i;
	  if(f==1)B.pb(i);
	  else A.pb(i);
	}
	//cout<<123<<endl;
	if(A.size()>=2){
	  int k;
	  int l=0;
	  //cout<<j<<endl;
	  // cout<<456<<endl;
	  for(int i=j+1;i<n;i+=2){
	    l=0;
	    if(i==n-1){
	      vector<int> m;
	      m.pb(0);
	      m.pb(i);
	      int f=use_machine(m);
	      if(f==0)A.pb(i);
		k=i+1;
		continue;
	    }
	    if(A.size()>=100 or B.size()>=100)break;
	    k=i+2;
	    vector<int> m;
	    m.pb(i);
	    m.pb(A[l]);
	    l++;
	    m.pb(i+1);
	    m.pb(A[l]);
	    int f=use_machine(m);
	    if(f==3){
	      B.pb(i+1);
	      B.pb(i);
	    }
	    if(f==2){
	      B.pb(i+1);
	      A.pb(i);
 	    }
	    if(f==1){
	      B.pb(i);
	      A.pb(i+1);
	    }
	    if(f==0){
	      A.pb(i);
	      A.pb(i+1);
	    }
	  }
	  // for(auto i:A)cout<<i<<" ";
	  //cout<<endl;
	  //cout<<A.size()<<endl;
	  if(A.size()>=100){
	    int ans=n-int(A.size());
	    vector<int> m;
	    while(k<n){
	      m.clear();
	      int l=0;
	      while(m.size()<200 and k<n){
		m.pb(A[l]);
		l++;
		m.pb(k);
		k++;
	      }
	      int f=use_machine(m);
	      f=(f+1)/2;
	      ans-=f;
	    }
	    return ans;
	  }
	  int ans=int(A.size());
	  //cout<<ans<<endl;
	  vector<int> m;
	  while(k<n){
	    m.clear();
	    int l=0;
	    while(m.size()<200 and k<n){
	      m.pb(B[l]);
	      l++;
	      m.pb(k);
	      k++;
	    }
	    int f=use_machine(m);
	    f=(f+1)/2;
	    ans+=f;
	  }
	  return ans;
	}
	int k;
	int l;
	for(int i=j+1;i<n;i+=2){
	  l=0;
	  if(i==n-1){
	    vector<int> m;
	    m.pb(0);
	    m.pb(i);
	    int f=use_machine(m);
	    if(f==0)A.pb(i);
	    k=i+2;
	    continue;
	  }
	    if(A.size()>=100 or B.size()>=100)break;
	    k=i+1;
	    vector<int> m;
	    m.pb(i);
	    m.pb(B[l]);
	    l++;
	    m.pb(i+1);
	    m.pb(B[l]);
	    int f=use_machine(m);
	    if(f==3){
	      A.pb(i+1);
	      A.pb(i);
	    }
	    if(f==2){
	      A.pb(i+1);
	      B.pb(i);
 	    }
	    if(f==1){
	      B.pb(i+1);
	      A.pb(i);
	    }
	    if(f==0){
	      B.pb(i);
	      B.pb(i+1);
	    }
	  }
	if(A.size()>=100){
	  vector<int> m;
	  int ans=n-int(A.size());
	  while(k<n){
	    m.clear();
	    int l=0;
	    while(k<n and m.size()<200){
	      m.pb(k);
	      k++;
	      m.pb(A[l]);
	      l++;
	    }
	    int f=use_machine(m);
	    f=(f+1)/2;
	    ans-=f;
	  }
	  return ans;
	}
	vector<int> m;
	int ans=A.size();
	while(k<n){
	  m.clear();
	  int l=0;
	  while(k<n and m.size()<200){
	    m.pb(k);
	    k++;
	    m.pb(B[l]);
	    l++;
	  }
	  int f=use_machine(m);
	  f=(f+1)/2;
	  ans+=f;
	}
	return ans;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:10:6: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
   10 |  int j;
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...