Submission #409382

#TimeUsernameProblemLanguageResultExecution timeMemory
409382Carmel_Ab1Counting Mushrooms (IOI20_mushrooms)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "mushrooms.h" #include "stub.cpp" using namespace std; #define pb push_back typedef vector<int> vi; typedef long long ll; int ceil(int a,int b){ int ans=a/b; if(a%b) ans++; return ans; } int count_mushrooms(int n) { int ans=1; vi o,z,a(n,-1); a[0]=0; z.pb(0); /* if(n<=226){ for(int i=2; i<n; i++) ans+=1- use_machine({0,i}); return ans; }*/ if(use_machine({0,1})){ o.pb(1); a[1]=1; } else{ ans++; a[1]=0; z.pb(1); } int first=1; const int k=sqrt(n); bool z2=z.size()==2; for(int i=2;z2 && o.size()<k && z.size()<k;first+=2, i+=2){ int res= use_machine({z[0],i,z[1],i+1}); if(res==0){ ans+=2; z.pb(i); z.pb(i+1); a[i]=a[i+1]=0; } else if(res==1){ ans++; z.pb(i); o.pb(i+1); a[i]=0,a[i+1]=1; } else if(res==2){ ans++; o.pb(i); z.pb(i+1); a[i]=1,a[i+1]=0; } else if(res==3){ o.pb(i); o.pb(i+1); a[i]=1,a[i+1]=1; } } for(int i=2;!z2 && o.size()<k && z.size()<k;first+=2, i+=2){ int res= use_machine({o[0],i,o[1],i+1}); if(res==0){ o.pb(i); o.pb(i+1); a[i]=a[i+1]=1; } else if(res==1){ ans++; o.pb(i); z.pb(i+1); a[i]=1,a[i+1]=0; } else if(res==2){ ans++; z.pb(i); o.pb(i+1); a[i]=0,a[i+1]=1; } else if(res==3){ ans+=2; z.pb(i); z.pb(i+1); a[i]=0,a[i+1]=0; } } vi left; for(int i=0; i<n;i++) if(a[i]==-1) left.pb(i); if(o.size()>z.size()){ for(int i=first,j=0; i<n;j=0, i++){ if(a[i]!=-1)continue; vi cur; while(left.size() && cur.size()+2<=n && j<o.size()){ cur.pb(o[j]); cur.pb(left.back()); left.pop_back(); j++; } if(cur.size()>=2) ans+= ceil(use_machine(cur),2); } } else{ for(int i=first,j=0; i<n;j=0, i++){ if(a[i]!=-1)continue; int in=0; vi cur; while(left.size() && cur.size()+2<=n && j<z.size()){ cur.pb(z[j]); cur.pb(left.back()); left.pop_back(); j++; in++; } if(cur.size()>=2) ans+= in-ceil(use_machine(cur),2); } } return ans; }

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:43:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   43 |     for(int i=2;z2 && o.size()<k && z.size()<k;first+=2, i+=2){
      |                       ~~~~~~~~^~
mushrooms.cpp:43:45: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   43 |     for(int i=2;z2 && o.size()<k && z.size()<k;first+=2, i+=2){
      |                                     ~~~~~~~~^~
mushrooms.cpp:70:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   70 |     for(int i=2;!z2 && o.size()<k && z.size()<k;first+=2, i+=2){
      |                        ~~~~~~~~^~
mushrooms.cpp:70:46: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   70 |     for(int i=2;!z2 && o.size()<k && z.size()<k;first+=2, i+=2){
      |                                      ~~~~~~~~^~
mushrooms.cpp:107:46: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  107 |             while(left.size() && cur.size()+2<=n && j<o.size()){
      |                                  ~~~~~~~~~~~~^~~
mushrooms.cpp:107:54: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |             while(left.size() && cur.size()+2<=n && j<o.size()){
      |                                                     ~^~~~~~~~~
mushrooms.cpp:122:46: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  122 |             while(left.size() && cur.size()+2<=n && j<z.size()){
      |                                  ~~~~~~~~~~~~^~~
mushrooms.cpp:122:54: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |             while(left.size() && cur.size()+2<=n && j<z.size()){
      |                                                     ~^~~~~~~~~
/usr/bin/ld: /tmp/ccObT8dI.o: in function `use_machine(std::vector<int, std::allocator<int> >)':
stub.cpp:(.text+0x150): multiple definition of `use_machine(std::vector<int, std::allocator<int> >)'; /tmp/ccM0FyCG.o:mushrooms.cpp:(.text+0x160): first defined here
/usr/bin/ld: /tmp/ccObT8dI.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccM0FyCG.o:mushrooms.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status