Submission #346428

#TimeUsernameProblemLanguageResultExecution timeMemory
346428SecretK버섯 세기 (IOI20_mushrooms)C++14
0 / 100
1 ms384 KiB
#include "mushrooms.h"
#include<bits/stdc++.h>
 
/*int count_mushrooms(int n) {  10 point
	std::vector<int> m;
	bool a = 0;
	int ans = 1;
	for (int i = 0; i < n-1; i++){
		if(use_machine({i,i+1}) == 1){
			if(a) a = 0;
			else a = 1;
		}
		if(!a) ans++;
	}
	return ans;
}*/

int count_mushrooms(int n){
	std::vector<int> m;
	bool a = 0;
	int ans = 1,i,t,j;
	for(i = 0;i < n-2;i+=2){
		if(a){
			t = use_machine({i,i+1,i+2});
			if(t == 1){
				a = 0;
				if(use_machine({j,j+1})) ans += 2;
				else ans++;
			}
			if(t == 2){
				ans++;
			}
		}
		else{
			t = use_machine({i,i+1,i+2});
			if(t == 0) ans += 2;
			if(t == 1){
				a = 1;
				if(use_machine({j,j+1}));
				else ans++;
			}
			if(t == 2){
				ans++;
			}
		}
	}
	if(i < n-1){
		if(a){
			if(use_machine({i,i+1})) ans++;
		}
		else{
			if(!use_machine({i,i+1})) ans++; 
		}
	}
	return ans;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:27:19: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |     if(use_machine({j,j+1})) ans += 2;
      |        ~~~~~~~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...