백준 1920번 "수찾기" [Hash의 Rehash 과정의 문제]

2026. 1. 29. 12:44·Coding Test/Hash

문제

 

 

 

---------------------------------------------------------------------------------------------------------------------------------------------------------------

 

문제 접근 순서.

 

1. 어떠한 원소를 찾아야 하는 문제이므로 hash 자료형을 이용할 생각. 

 

2. hash에서 rehash(재해싱)에 관한 문제가 생길수 있으므로 반드시 미리 공간을 확보한 다음 

    사용하기 ( 안할 시  N=100000 기준 으로 O(N) 리해싱 복잡도가 14번 나오므로 시간 초과를 유발함) 

 

 

---------------------------------------------------------------------------------------------------------------------------------------------------------------

 

#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std; 

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int i_inputCount; 
	unordered_set<int> m_set; 

	cin >> i_inputCount; 
	m_set.reserve(i_inputCount);


	for(int i=0; i<i_inputCount; i++)
	{
		int iNumber; 
		cin >> iNumber;
		m_set.emplace(iNumber);
	}

	int i_FindCase;
	cin >> i_FindCase; 

	for(int i=0; i<i_FindCase; i++)
	{
		int i_FindNumber;
		cin >> i_FindNumber; 

		if(m_set.find(i_FindNumber)!= m_set.end())
		{
			cout << "1" << "\n";
		}

		else
			cout << "0" << "\n";
	}
	
}

 

'Coding Test > Hash' 카테고리의 다른 글

프로그래머스 [Level1] 완주하지 못한 선수 [Hash]  (0) 2025.11.09
'Coding Test/Hash' 카테고리의 다른 글
  • 프로그래머스 [Level1] 완주하지 못한 선수 [Hash]
seonhwan2547
seonhwan2547
seonhwan2547 님의 블로그 입니다.
  • seonhwan2547
    seonhwan2547 님의 블로그
    seonhwan2547
  • 전체
    오늘
    어제
    • 분류 전체보기 (80)
      • Unreal Project (17)
        • Khazan 모작 프로젝트 (2)
        • Unreal Study (10)
        • Blueprint (5)
      • Directx11 Project (11)
        • Thymesia 팀 프로젝트 (8)
        • Kaku Ancient Seal 개인 프로젝트 (2)
        • Thymesia Animation Tool 개발 (0)
      • Algorithm (6)
        • Binary_Search (2)
        • Greedy (1)
        • Dynamic Programming (1)
        • A-star (1)
      • Coding Test (31)
        • Brutal Force (2)
        • Sort (5)
        • DFS (3)
        • Binary_Search (4)
        • BFS (6)
        • Hash (2)
        • Dynamic Programming (6)
        • Greedy (1)
        • BackTracking (1)
        • Binary_Tree (1)
      • STL Container (1)
        • unorded_set (0)
        • priority_queue (1)
      • C++ 공부 및 몰랐던점 (8)
        • Smart pointer (1)
      • Visual Studio 설정관련 공부 (1)
      • Console Project (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 블로그 소개
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    blueprint
    hash
    CodingTest
    Game Programming
    GameProgramming
    Unreal
    Unreal Engine
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
seonhwan2547
백준 1920번 "수찾기" [Hash의 Rehash 과정의 문제]