Submission #411656

#TimeUsernameProblemLanguageResultExecution timeMemory
411656JUANDI321Counting Mushrooms (IOI20_mushrooms)C++17
Compilation error
0 ms0 KiB
#include "mushrooms.h"
#include <iostream>
#include <vector>
 
using namespace std;
vector<int> x;
int count_mushrooms(int n)
{
	int m = (n-1)%4;
    long long A = 1;
    for(int i = 1; i<n-m; i+=4)
    {
	        x.push_back(i);
  	    	x.push_back(i+1);
			x.push_back(i+2);
			x.push_back(i+3);
			int p = use_machine(x);
        	if(p == 0)
        	{
        		x.push_back(0);
        		int pp = use_machine(x);
        		if(pp == 0)A+=4;
			}
			if(p==1)
			{
				x.clear();
				x.push_back(i+1);
				x.push_back(0);
				x.push_back(i+2);		
    	    	int pp = use_machine(x);
        		if(pp == 2)A+=1;
        		if(pp == 1)A+=2;
	        	if(pp == 0)A+=3;
			}
			if(p==2)
			{
				x.push_back(0);
	        	int pp = use_machine(x);
    	    	if(pp == 2)A+=3;
			}
        	if(p==3)A+=2;
		}
        x.clear();
    }
		x.clear();
		x.push_back(0);
    	for(int i = n-m; i<n; i++)
    	{
     		x.push_back(i);
     	   	int p = use_machine(x);
     	   	if(p == 0)A++;
      	  	x.pop_back();
    	}
    return A;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:44:5: warning: no return statement in function returning non-void [-Wreturn-type]
   44 |     }
      |     ^
mushrooms.cpp: At global scope:
mushrooms.cpp:45:3: error: 'x' does not name a type
   45 |   x.clear();
      |   ^
mushrooms.cpp:46:3: error: 'x' does not name a type
   46 |   x.push_back(0);
      |   ^
mushrooms.cpp:47:6: error: expected unqualified-id before 'for'
   47 |      for(int i = n-m; i<n; i++)
      |      ^~~
mushrooms.cpp:47:23: error: 'i' does not name a type
   47 |      for(int i = n-m; i<n; i++)
      |                       ^
mushrooms.cpp:47:28: error: 'i' does not name a type
   47 |      for(int i = n-m; i<n; i++)
      |                            ^
mushrooms.cpp:54:5: error: expected unqualified-id before 'return'
   54 |     return A;
      |     ^~~~~~
mushrooms.cpp:55:1: error: expected declaration before '}' token
   55 | }
      | ^