# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
707272 | NemanjaSo2005 | 버섯 세기 (IOI20_mushrooms) | C++14 | 10 ms | 472 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "mushrooms.h"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll N,sta[20005],D=150;
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;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |