제출 #424301

#제출 시각아이디문제언어결과실행 시간메모리
424301ApiramCounting Mushrooms (IOI20_mushrooms)C++14
컴파일 에러
0 ms0 KiB
#include "mushrooms.h"
#include<bits/stdc++.h>
using namespace std;

int count_mushrooms(int n) {
	vector<int>a,b;
	a.push_back(a);
	int ans=0;
	vector<int>both;
	for (int i =1;i<n;++i){
		both.push_back(i);
		if (both.size()!=max(a.size(),b.size()))continue;
		if (a.size()>b.size()){
			vector<int>cur;
			for (int i =0;i<both.size();++i){
				cur.push_back(both[i]);
				cur.push_back(a[i]);
			}
			int k = use_machine(cur);
			ans+=(k + 1)/2 - 1;
			if (k%2==1){
				a.push_back(cur[0]);
			}
			else b.push_back(cur[0]);
		}
		else {
			vector<int>cur;
			for (int i =0;i<both.size();++i){
				cur.push_back(both[i]);
				cur.push_back(b[i]);
			}
			int k = use_machine(cur);
			ans+=cur.size() - (k + 1)/2 ;
			if (k%2==1){
				b.push_back(cur[0]);
			}
			else a.push_back(cur[0]);
		}
		both.clear();
	}
	if (!both.empty()){
		if (both.size()!=max(a.size(),b.size()))continue;
		if (a.size()>b.size()){
			vector<int>cur;
			for (int i =0;i<both.size();++i){
				cur.push_back(both[i]);
				cur.push_back(a[i]);
			}
			int k = use_machine(cur);
			ans+=(k + 1)/2 - 1;
			if (k%2==1){
				a.push_back(cur[0]);
			}
			else b.push_back(cur[0]);
		}
		else {
			vector<int>cur;
			for (int i =0;i<both.size();++i){
				cur.push_back(both[i]);
				cur.push_back(b[i]);
			}
			int k = use_machine(cur);
			ans+=cur.size() - (k + 1)/2 ;
			if (k%2==1){
				b.push_back(cur[0]);
			}
			else a.push_back(cur[0]);
		}
	}
	return ans + a.size();
}

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

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:7:15: error: no matching function for call to 'std::vector<int>::push_back(std::vector<int>&)'
    7 |  a.push_back(a);
      |               ^
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 = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = 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 'std::vector<int>' to 'const value_type&' {aka 'const 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 = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = 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 'std::vector<int>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
mushrooms.cpp:15:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |    for (int i =0;i<both.size();++i){
      |                  ~^~~~~~~~~~~~
mushrooms.cpp:28:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |    for (int i =0;i<both.size();++i){
      |                  ~^~~~~~~~~~~~
mushrooms.cpp:42:43: error: continue statement not within a loop
   42 |   if (both.size()!=max(a.size(),b.size()))continue;
      |                                           ^~~~~~~~
mushrooms.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |    for (int i =0;i<both.size();++i){
      |                  ~^~~~~~~~~~~~
mushrooms.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |    for (int i =0;i<both.size();++i){
      |                  ~^~~~~~~~~~~~