Submission #600564

#TimeUsernameProblemLanguageResultExecution timeMemory
600564kig9981Counting Mushrooms (IOI20_mushrooms)C++17
Compilation error
0 ms0 KiB
#include "mushrooms.h" #include <bits/stdc++.h> #ifdef NON_SUBMIT #define TEST(n) (n) #define tout cerr #else #define TEST(n) ((void)0) #define tout cin #endif using namespace std; vector<pair<int,int>> V; vector<int> A, B, Q; int D[3]; void query2() { int a=V[0].first, b=V[1].first, r; if(A.size()>1) { r=use_machine({A[0],a,A[1],b}); if(r&1) { B.push_back(b); A.push_back(V[1].second); } else { A.push_back(b); B.push_back(V[1].second); } if(r>1) { B.push_back(a); A.push_back(V[0].second); } else { A.push_back(a); V.push_back(V[0].second); } } else { r=use_machine({B[0],a,B[1],b}); if(r&1) { A.push_back(b); B.push_back(V[1].second); } else { B.push_back(b); A.push_back(V[1].second); } if(r>1) { A.push_back(a); B.push_back(V[0].second); } else { B.push_back(a); A.push_back(V[0].second); } } } void query3() { int a, b, c, r; if(Q.size()==1) { a=Q.back(); Q.pop_back(); if(use_machine({0,a})) B.push_back(a); else A.push_back(a); } else if(Q.size()==2) { a=Q.back(); Q.pop_back(); b=Q.back(); Q.pop_back(); if(A.size()>1) { r=use_machine({A[0],a,A[1],b}); if(r&1) B.push_back(b); else A.push_back(b); if(r>1) B.push_back(a); else A.push_back(a); } else { r=use_machine({B[0],a,B[1],b}); if(r&1) A.push_back(b); else B.push_back(b); if(r>1) A.push_back(a); else B.push_back(a); } } else { a=Q.back(); Q.pop_back(); b=Q.back(); Q.pop_back(); c=Q.back(); Q.pop_back(); if(A.size()>1) { r=use_machine({A[0],a,A[1],b,c}); if(r&1) B.push_back(c); else A.push_back(c); if(r==0) { A.push_back(a); A.push_back(b); } else if(r==1) { A.push_back(a); Q.push_back(b); } else if(r==2) { V.emplace_back(a,b); if(V.size()>1) query2(); } else if(r==3) { B.push_back(a); Q.push_back(b); } else { B.push_back(a); B.push_back(b); } } else { r=use_machine({B[0],a,B[1],b,c}); if(r&1) A.push_back(c); else B.push_back(c); if(r==0) { B.push_back(a); B.push_back(b); } else if(r==1) { B.push_back(a); Q.push_back(b); } else if(r==2) { V.emplace_back(a,b); if(V.size()>1) query2(); } else if(r==3) { A.push_back(a); Q.push_back(b); } else { A.push_back(a); A.push_back(b); } } } } int query() { int m=min(Q.size(),max(A.size(),B.size())), r; vector<int> I; if(A.size()>=m) { for(int i=0;i<m;i++) { I.push_back(A[i]); I.push_back(Q.back()); Q.pop_back(); } r=use_machine(I); if(r&1) B.push_back(I.back()); else A.push_back(I.back()); return m-1-(r>>1); } else { for(int i=0;i<m;i++) { I.push_back(B[i]); I.push_back(Q.back()); Q.pop_back(); } r=use_machine(I); if(r&1) A.push_back(I.back()); else B.push_back(I.back()); return r>>1; } } int count_mushrooms(int n) { int ret=0; mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count()); if(n-1<=226) { ret=1; for(int i=1;i<n;i++) ret+=!use_machine({0,i}); return ret; } for(int i=1;i<n;i++) Q.push_back(i); shuffle(Q.begin(),Q.end(),mt); A.push_back(0); while(max(A.size(),B.size())<2) { int c=Q.back(); Q.pop_back(); if(use_machine({0,c})) B.push_back(c); else A.push_back(c); } for(int i=0;i<100;i++) { if(Q.empty()) break; query3(); } if(V.size()) { if(use_machine({0,V[0].first})) { B.push_back(V[0].first); A.push_back(V[0].second); } else { A.push_back(V[0].first); B.push_back(V[0].second); } } while(Q.size()) ret+=query(); return ret+A.size(); }

Compilation message (stderr)

mushrooms.cpp: In function 'void query2()':
mushrooms.cpp:37:27: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(int&)'
   37 |    V.push_back(V[0].second);
      |                           ^
In file included from /usr/include/c++/10/vector:67,
                 from mushrooms.h:1,
                 from mushrooms.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from 'int' to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from 'int' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
mushrooms.cpp: In function 'int query()':
mushrooms.cpp:148:13: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  148 |  if(A.size()>=m) {
      |     ~~~~~~~~^~~