제출 #409374

#제출 시각아이디문제언어결과실행 시간메모리
409374Carmel_Ab1버섯 세기 (IOI20_mushrooms)C++17
컴파일 에러
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(0); } if(use_machine({0,2})){ o.pb(2); a[2]=1; } else { ans++; a[2] = 0; z.pb(2); } int first=1; const int k=100; bool z2=z.size()==2; for(int i=3;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=3;!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; }

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

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:116:46: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  116 |             while(left.size() && cur.size()+2<=n && j<o.size()){
      |                                  ~~~~~~~~~~~~^~~
mushrooms.cpp:116:54: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |             while(left.size() && cur.size()+2<=n && j<o.size()){
      |                                                     ~^~~~~~~~~
mushrooms.cpp:131:46: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  131 |             while(left.size() && cur.size()+2<=n && j<z.size()){
      |                                  ~~~~~~~~~~~~^~~
mushrooms.cpp:131:54: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  131 |             while(left.size() && cur.size()+2<=n && j<z.size()){
      |                                                     ~^~~~~~~~~
/usr/bin/ld: /tmp/ccfqyLyH.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/cc9TRsfH.o:mushrooms.cpp:(.text+0x160): first defined here
/usr/bin/ld: /tmp/ccfqyLyH.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc9TRsfH.o:mushrooms.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status