제출 #346158

#제출 시각아이디문제언어결과실행 시간메모리
346158poom2904버섯 세기 (IOI20_mushrooms)C++14
0 / 100
2 ms364 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; int cnt_A = 1,cnt_B = 0; vector<int> A = {0},B; int i=1; const int cri=100;//if cnt_A or cnt_B >cri, do func2 void func1() { while(max(cnt_A,cnt_B)<2) { vector<int> vec = {0,i}; if(use_machine(vec)) { cnt_B++; B.push_back(i); } else { cnt_A++; A.push_back(i); } i++; } while((min(cnt_A,cnt_B)<2 || max(cnt_A,cnt_B)<3) && max(cnt_A,cnt_B)<cri) { bool is_swapped = false; if(cnt_A<2) { swap(cnt_A,cnt_B); swap(A,B); is_swapped = true; } vector<int> vec = {i,A[0],i+1,A[1]}; int res = use_machine(vec); if(res==0) { cnt_A+=2; A.push_back(i); A.push_back(i+1); } else if(res==1) { cnt_A++; cnt_B++; A.push_back(i+1); B.push_back(i); } else if(res==2) { cnt_A++; cnt_B++; A.push_back(i); B.push_back(i+1); } else { cnt_B+=2; B.push_back(i); B.push_back(i+1); } if(is_swapped) { swap(cnt_A,cnt_B); swap(A,B); } i+=2; } while(max(cnt_A,cnt_B)<cri) { bool is_swapped = false; if(cnt_A<cnt_B) { swap(cnt_A,cnt_B); swap(A,B); is_swapped = true; } vector<int> vec = {i,A[0],i+1,A[1],i+2,A[2]}; int res = use_machine(vec); if(res&1) { cnt_A++; A.push_back(i); } else { cnt_B++; B.push_back(i); } if(res-(res&1)==0) { A.push_back(i+1); A.push_back(i+2); cnt_A+=2; i+=3; } else if(res-(res&1)==4) { B.push_back(i+1); B.push_back(i+2); cnt_B+=2; i+=3; } else { i++; vec = {i,B[0],i+1,B[1],A[0],i+2,A[1]}; res = use_machine(vec); if(res&1) { cnt_B++; B.push_back(i); } else { cnt_A++; A.push_back(i); } if(res==1 || res==2) { cnt_A++; cnt_B++; A.push_back(i+2); B.push_back(i+1); } else if(res==5 || res==6) { cnt_A++; cnt_B++; A.push_back(i+1); B.push_back(i+2); } else if(res==3) { cnt_A+=2; A.push_back(i+1); A.push_back(i+2); } else if(res==4) { cnt_B+=2; B.push_back(i+1); B.push_back(i+2); } i+=3; } if(is_swapped) { swap(cnt_A,cnt_B); swap(A,B); } } } void func2(int n) { while(i<n) { int minn = min(int(A.size()),n-i); vector<int> vec(minn*2); for(int j=0;j<minn;j++) { vec[j*2] = i+j; vec[j*2+1] = A[j]; } int res = use_machine(vec); if((res&1)==0) { cnt_A++; A.push_back(i); } cnt_A += minn-1-res/2; i+=minn; } } int count_mushrooms(int n) { if(n<=227) { while(i<n) { vector<int> vec = {0,i}; if(use_machine(vec))cnt_B++; else cnt_A++; i++; } return cnt_A; } func1(); func2(n); return cnt_A; }
#Verdict Execution timeMemoryGrader output
Fetching results...