Submission #304491

#TimeUsernameProblemLanguageResultExecution timeMemory
304491arnold518Counting Mushrooms (IOI20_mushrooms)C++14
92.24 / 100
9 ms384 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2e4; const int SQ = 100; int N; int query(vector<int> V) { return use_machine(V); } int naive() { int ans=1; for(int i=1; i+1<N; i+=2) { ans+=2-query({i, 0, i+1}); } if(N%2==0) ans+=1-query({0, N-1}); return ans; } int count_mushrooms(int _N) { N=_N; if(N<=2*SQ) return naive(); vector<int> A, B; A.push_back(0); int p, ans=0; for(p=1; p<=2; p++) { if(query({0, p})) B.push_back(p); else A.push_back(p); } if(A.size()>=2) { for(; p+1<N && A.size()<SQ && B.size()<SQ; p+=2) { int t=query({A[0], p, A[1], p+1}); if(t==0) A.push_back(p), A.push_back(p+1); else if(t==1) A.push_back(p), B.push_back(p+1); else if(t==2) B.push_back(p), A.push_back(p+1); else B.push_back(p), B.push_back(p+1); } } else { for(; p+1<N && A.size()<SQ && B.size()<SQ; p+=2) { int t=query({B[0], p, B[1], p+1}); if(t==0) B.push_back(p), B.push_back(p+1); else if(t==1) B.push_back(p), A.push_back(p+1); else if(t==2) A.push_back(p), B.push_back(p+1); else A.push_back(p), A.push_back(p+1); } } ans=0; while(p<N) { if(A.size()>B.size()) { int i, j; vector<int> V; for(j=0; p<N && j<A.size(); p++, j++) { V.push_back(A[j]); V.push_back(p); } int t=query(V); if(t%2) B.push_back(V.back()); else A.push_back(V.back()); ans+=j-t/2-1; } else { int i, j; vector<int> V; for(j=0; p<N && j<B.size(); p++, j++) { V.push_back(B[j]); V.push_back(p); } int t=query(V); if(t%2) A.push_back(V.back()); else B.push_back(V.back()); ans+=t/2; } } return ans+A.size(); }

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:77:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |    for(j=0; p<N && j<A.size(); p++, j++)
      |                    ~^~~~~~~~~
mushrooms.cpp:75:8: warning: unused variable 'i' [-Wunused-variable]
   75 |    int i, j;
      |        ^
mushrooms.cpp:91:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |    for(j=0; p<N && j<B.size(); p++, j++)
      |                    ~^~~~~~~~~
mushrooms.cpp:89:8: warning: unused variable 'i' [-Wunused-variable]
   89 |    int i, j;
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...