Understanding Fence Painting Problem Solution

Solution:

#include <vector>
using namespace std;

int main() {
	// Use standard input to read from "paint.in"
	freopen("paint.in", "r", stdin);
	// Use standard output to write to "paint.out"
	freopen("paint.out", "w", stdout);

	vector<bool> cover(100);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	for (int i = a; i < b; i++) { cover[i] = true; }
	for (int i = c; i < d; i++) { cover[i] = true; }

	int ans = 0;
	for (int i = 0; i < cover.size(); i++) { ans += cover[i]; }
	cout << ans << endl;
}

I am unsure of what the code
vector<bool> cover(100);
is doing. If it was defining an array it would use brackets, and I am not certain what “vector” does in the code since I have not learned how to use it before. Can you please help me? Thanks!

try asking chatgpt

Thank you for your suggestion. I understand now! :slight_smile: