๐Ÿ™‡โ€โ™€๏ธ[Silver V] ์ง‘ํ•ฉ - 11723

๋ฌธ์ œ ๋งํฌ

์„ฑ๋Šฅ ์š”์•ฝ

๋ฉ”๋ชจ๋ฆฌ: 2024 KB, ์‹œ๊ฐ„: 708 ms

๋ถ„๋ฅ˜

๋น„ํŠธ๋งˆ์Šคํ‚น, ๊ตฌํ˜„

์ œ์ถœ ์ผ์ž

2023๋…„ 12์›” 21์ผ 00:55:24

๋ฌธ์ œ ์„ค๋ช…

๋น„์–ด์žˆ๋Š” ๊ณต์ง‘ํ•ฉ S๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์•„๋ž˜ ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

  • add x: S์— x๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค. (1 โ‰ค x โ‰ค 20) S์— x๊ฐ€ ์ด๋ฏธ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋Š” ์—ฐ์‚ฐ์„ ๋ฌด์‹œํ•œ๋‹ค.
  • remove x: S์—์„œ x๋ฅผ ์ œ๊ฑฐํ•œ๋‹ค. (1 โ‰ค x โ‰ค 20) S์— x๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ์—๋Š” ์—ฐ์‚ฐ์„ ๋ฌด์‹œํ•œ๋‹ค.
  • check x: S์— x๊ฐ€ ์žˆ์œผ๋ฉด 1์„, ์—†์œผ๋ฉด 0์„ ์ถœ๋ ฅํ•œ๋‹ค. (1 โ‰ค x โ‰ค 20)
  • toggle x: S์— x๊ฐ€ ์žˆ์œผ๋ฉด x๋ฅผ ์ œ๊ฑฐํ•˜๊ณ , ์—†์œผ๋ฉด x๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค. (1 โ‰ค x โ‰ค 20)
  • all: S๋ฅผ {1, 2, ..., 20} ์œผ๋กœ ๋ฐ”๊พผ๋‹ค.
  • empty: S๋ฅผ ๊ณต์ง‘ํ•ฉ์œผ๋กœ ๋ฐ”๊พผ๋‹ค.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ์ˆ˜ํ–‰ํ•ด์•ผ ํ•˜๋Š” ์—ฐ์‚ฐ์˜ ์ˆ˜ M (1 โ‰ค M โ‰ค 3,000,000)์ด ์ฃผ์–ด์ง„๋‹ค.

๋‘˜์งธ ์ค„๋ถ€ํ„ฐ M๊ฐœ์˜ ์ค„์— ์ˆ˜ํ–‰ํ•ด์•ผ ํ•˜๋Š” ์—ฐ์‚ฐ์ด ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค.

์ถœ๋ ฅ

check ์—ฐ์‚ฐ์ด ์ฃผ์–ด์งˆ๋•Œ๋งˆ๋‹ค, ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

๐Ÿš€ํ’€์ด

container๋กœ ๋ฒกํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํ’€์—ˆ๋‹ค.

x์˜ ๊ฐ’์ด 1<=20์ด๋ฏ€๋กœ ์ „์ฒด๋ฅผ ์ˆœํšŒํ•ด๋„ ์‹œ๊ฐ„ ์ œ์•ฝ์ด ๊ฑธ๋ฆฌ์ง€ ์•Š์„๊ฑฐ๋ผ๊ณ  ํŒ๋‹จํ–ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

๊ฐ™์€ ๊ฐ’์ด ๋‘ ๋ฒˆ ๋“ค์–ด๊ฐˆ ์ผ์ด ์—†์œผ๋ฏ€๋กœ ๊ฐ ์ธ๋ฑ์Šค์—์„œ ๊ฐ’์ด ์žˆ๋ƒ ์—†๋ƒ๋กœ ํŒ๋‹จํ•ด์ฃผ์—ˆ๋‹ค.

vector<int> vec;
int n;

void solve()
{
	cin >> n;

	vec = vector<int>(21);

	while (n > 0)
	{
		string str;
		cin >> str;

		if (str == "add")
		{
			int temp;
			cin >> temp;
			if (vec[temp] == 0)
				vec[temp]++;
		}
		else if (str == "remove")
		{
			int temp;
			cin >> temp;
			if (vec[temp] == 1)
				vec[temp]--;
		}
		else if (str == "check")
		{
			int temp;
			cin >> temp;
			if (vec[temp] == 1)
				cout << 1 << '\n';
			else
				cout << 0 << '\n';
		}
		else if (str == "toggle")
		{
			int temp;
			cin >> temp;
			if (vec[temp] == 1)
				vec[temp]--;
			else
				vec[temp]++;
		}
		else if (str == "all")
		{
			for (int i = 1; i <= 20; ++i)
				vec[i] = 1;
		}
		else if (str == "empty")
		{
			for (int i = 1; i <= 20; ++i)
				vec[i] = 0;
		}

		n--;
	}
}

๐Ÿš€์ „์ฒด ์ฝ”๋“œ

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include<iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> vec;
int n;

void solve()
{
	cin >> n;

	vec = vector<int>(21);

	while (n > 0)
	{
		string str;
		cin >> str;

		if (str == "add")
		{
			int temp;
			cin >> temp;
			if (vec[temp] == 0)
				vec[temp]++;
		}
		else if (str == "remove")
		{
			int temp;
			cin >> temp;
			if (vec[temp] == 1)
				vec[temp]--;
		}
		else if (str == "check")
		{
			int temp;
			cin >> temp;
			if (vec[temp] == 1)
				cout << 1 << '\n';
			else
				cout << 0 << '\n';
		}
		else if (str == "toggle")
		{
			int temp;
			cin >> temp;
			if (vec[temp] == 1)
				vec[temp]--;
			else
				vec[temp]++;
		}
		else if (str == "all")
		{
			for (int i = 1; i <= 20; ++i)
				vec[i] = 1;
		}
		else if (str == "empty")
		{
			for (int i = 1; i <= 20; ++i)
				vec[i] = 0;
		}

		n--;
	}
}

int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("input.txt", "rt", stdin);

	solve();

	return 0;
}

ํƒœ๊ทธ:

์นดํ…Œ๊ณ ๋ฆฌ:

์—…๋ฐ์ดํŠธ: