Submission #1070482

#TimeUsernameProblemLanguageResultExecution timeMemory
1070482noyancanturkRarest Insects (IOI22_insects)C++17
98.88 / 100
48 ms596 KiB
#include "insects.h" #include<iostream> int min_cardinality(int n) { int types[n]{},cert[n]{}; bool arein[n]{}; int last=0; auto push=[&](int i){ move_inside(i); arein[i]=1; }; auto pop=[&](int i){ move_outside(i); arein[i]=0; }; auto query=[&](){ last=press_button(); }; types[0]=cert[0]=1; push(0); int headcnt=1; for(int i=1;i<n;i++){ push(i); query(); if(last!=1){ types[i]=cert[i]=2; pop(i); }else headcnt+=types[i]=cert[i]=1; } last=1; int ans=1; int cnt=headcnt; int l=2,r=n/headcnt; while(l<=r){ int mid=l+r>>1; for(int i=0;i<n;i++){ if(mid<types[i]&&arein[i]&&mid<last){ pop(i),cnt--; query(); } } for(int i=0;i<n;i++){ if(arein[i]||mid<cert[i])continue; int llast=last; push(i),cnt++; query(); if(llast!=last)cert[i]=std::max(cert[i],last); types[i]=std::max(types[i],last); if(mid<last)pop(i),cnt--,last--; } if(cnt==headcnt*mid){ ans=mid; l=mid+1; }else{ r=cnt/headcnt; } } return ans; }

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:36:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |     int mid=l+r>>1;
      |             ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...