Notice
                              
                          
                        
                          
                          
                            Recent Posts
                            
                        
                          
                          
                            Recent Comments
                            
                        
                          
                          
                            Link
                            
                        
                    | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
                            Tags
                            
                        
                          
                          - OS
- SQL
- 백준 1253번
- 백준
- 의미와 무의미의 경계에서
- 트랜잭션 관리
- 민겸수
- UnrealMP
- 오손데이터읽기
- 셰그먼트트리
- 1967번
- 2단계로킹
- command not found
- objtofbx
- 비재귀셰그먼트
- C++
- 실습
- hackerank
- Security
- 1253번
- 데이터베이스 배움터
- oracle
- 1759번
- Linux
- FBX
- 언리얼 플러그인
- UActor
- 5639
- Unreal
- 언리얼 커스텀 플러그인
                            Archives
                            
                        
                          
                          - Today
- Total
fatalite
🏳 겹치는 건 싫어 - 20922번 백준 본문
문제
문제 난이도 : 실버 1
문제 분류 : 두 포인터
문제 풀이 및 코드
복잡...
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_set>
using namespace std;
void Init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main()
{
    //Initialize
    Init();
    //Input
    int n, k = 0;
    cin >> n >> k;
    vector<int> List;
    vector<int> Count(100001,0);
    for (int i = 0; i < n; ++i)
    {
        int Tmp;
        cin >> Tmp;
        List.push_back(Tmp);
    }
    //Main Logic
    int Start = 0;
    int End = 0;
    int Length = 0;
    while (true)
    {
        if (End >= n || Start >= n || Start > End) break;
        if (Count[List[End]] < k)
        {
            Count[List[End]]++;
            End++;
            Length = max(Length, End - Start);
        }
        else if(Count[List[End]] == k)
        {
            Count[List[Start]]--;
            Start++;
        }
    }
    cout << Length;
}'코딩 인터뷰 > C++' 카테고리의 다른 글
| 프로그래머스 C++ 삼각 달팽이 (0) | 2024.09.28 | 
|---|---|
| 구간 합 구하기 - 2042번 백준 (0) | 2023.10.01 | 
| 섬의 개수 - 4963번 백준 (0) | 2023.09.16 | 
| 점프 점프 - 11060번 백준 (0) | 2023.09.14 | 
| 🏳 쉬운 계단 수 / 10844번 백준 (0) | 2023.09.10 | 
