제출 #707270

#제출 시각아이디문제언어결과실행 시간메모리
707270NemanjaSo2005Counting Mushrooms (IOI20_mushrooms)C++14
80.43 / 100
10 ms596 KiB
#include "mushrooms.h"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll N,sta[20005],D=138;
bool inv;
vector<int> x,A,B,R;
stack<int> S;
int count_mushrooms(int n){
   N=n;
   if(N<=227){
      sta[0]=1;
      for(int i=0;i+1<N;i++){
         x.clear();
         x.push_back(i);
         x.push_back(i+1);
         sta[i+1]=sta[i]^use_machine(x);
      }
      ll res=0;
      for(int i=0;i<N;i++)
         res+=sta[i];
      return res;
   }
   ll res=1;
   for(int i=0;i<N;i++)
      sta[i]=2;
   sta[0]=1;
   A.push_back(0);
   for(int i=0;i+1<N;i++){
      if(A.size()>=D or B.size()>=D)
         break;
      //cout<<i<<endl;
      if((A.size()<2 and B.size()<2) or (i+2==N)){
         x.clear();
         x.push_back(i);
         x.push_back(i+1);
         sta[i+1]=sta[i]^use_machine(x);
          if(sta[i+1]==1){
            A.push_back(i+1);
            res++;
         }
         else
            B.push_back(i+1);
        // cout<<"DODAJEM "<<i+1<<endl;
      }
      else{
         if(A.size()>=2){
            x.clear();
            x.push_back(A[0]);
            x.push_back(i+1);
            x.push_back(A[1]);
            x.push_back(i+2);
            int r=use_machine(x);
            if(r>=2)
               sta[i+1]=0;
            else
               sta[i+1]=1;
            if(r%2==1)
               sta[i+2]=0;
            else
               sta[i+2]=1;
         }
         else{
            x.clear();
            x.push_back(B[0]);
            x.push_back(i+1);
            x.push_back(B[1]);
            x.push_back(i+2);
            int r=use_machine(x);
            if(r>=2)
               sta[i+1]=1;
            else
               sta[i+1]=0;
            if(r%2==1)
               sta[i+2]=1;
            else
               sta[i+2]=0;
         }
         if(sta[i+1]==1){
            A.push_back(i+1);
            res++;
         }
         else
            B.push_back(i+1);
 
         if(sta[i+2]==1){
            A.push_back(i+2);
            res++;
         }
         else
            B.push_back(i+2);
        // cout<<"DODAJEM "<<i+1<<endl;
       //  cout<<"DODAJEM "<<i+2<<endl;
         i++;
      }
   }
   if(A.size()>B.size()){
      R=A;
      inv=1;
   }
   else{
      R=B;
      inv=0;
   }
   for(int i=0;i<N;i++)
      if(sta[i]==2)
         S.push(i);
   int pok;
  // cout<<res<<endl;
   while(S.size()){
      x.clear();
      x.push_back(R[0]);
      pok=1;
      while(pok<R.size() and S.size()){
         x.push_back(S.top());
         S.pop();
         x.push_back(R[pok]);
         pok++;
      }
      bool dod=false;
      if(S.size()){
         dod=true;
         x.push_back(S.top());
         S.pop();
      }
      int r=use_machine(x);
      if(inv){
         res+=((x.size()-1)-r)/2;
         if(r%2==0 and dod)
            res++;
      }
      else{
         res+=(r)/2;
         if(r%2==1 and dod)
            res++;
      }
      //cout<<res<<endl;
   }
   return res;
}

컴파일 시 표준 에러 (stderr) 메시지

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:30:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   30 |       if(A.size()>=D or B.size()>=D)
      |          ~~~~~~~~^~~
mushrooms.cpp:30:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   30 |       if(A.size()>=D or B.size()>=D)
      |                         ~~~~~~~~^~~
mushrooms.cpp:114:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |       while(pok<R.size() and S.size()){
      |             ~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...