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
- 줄 세우기
- DirectX11
- NRVO
- 1563
- 오블완
- algorithm
- RootMotion
- C++
- UE5
- 티스토리챌린지
- winapi
- IFileDialog
- 팰린드롬 만들기
- 백준
- TObjectPtr
- 프로그래머스
- RVO
- Unreal Engine5
- C
- softeer
- 언리얼엔진5
- 2294
- UnrealEngine4
- Programmers
- GeeksForGeeks
- directx
- Frustum
- UnrealEngine5
- baekjoon
- const
Archives
- Today
- Total
Game Develop
[Algorithm]Baekjoon 13144번 :: List of Unique Numbers 본문
https://www.acmicpc.net/problem/13144
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <functional>
#include <sstream>
#include <memory.h>
#include <deque>
#include <set>
#include <unordered_set>
using namespace std;
long long n;
int arr[100001] = { 0 };
int check[100001] = { 0 };
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> arr[i];
}
long long answer = 0;
check[arr[1]] = 1;
int start = 1;
int end = 1;
for (int i = 0; i < n; ++i) // 카운팅용. i 안씀. n번만큼만 ++start함.
{
while (end + 1 <= n && check[arr[end + 1]] == 0)
{
++end;
++check[arr[end]]; // 체크 (수열에 포함)
}
answer += end - start + 1;
--check[arr[start]]; // 수열에서 제외
++start;
}
cout << answer;
}
|
cs |
중복된 숫자가 없는 연속된수열들의 개수를 구하는 문제이다.
투포인터를 이용해야만 적절한 시간내에 해결할 수 있다.
친절한 설명은 아래글이 굿
https://codingnotes.tistory.com/182
[백준 13144번] List of Unique Numbers (C++)
https://www.acmicpc.net/problem/13144 13144번: List of Unique Numbers 길이가 N인 수열이 주어질 때, 수열에서 연속한 1개 이상의 수를 뽑았을 때 같은 수가 여러 번 등장하지 않는 경우의 수를 구하는 프로그램
codingnotes.tistory.com
start를 한단계씩 올리는거는 결국 최대 n번이기 때문에 for문으로 했다.
'Algorithm > Baekjoon' 카테고리의 다른 글
[Algorithm]Baekjoon 2211번 :: 네트워크 복구 (0) | 2025.03.17 |
---|---|
[Algorithm]Baekjoon 1774번 :: 우주신과의 교감 (0) | 2025.03.17 |
[Algorithm]Baekjoon 16954번 :: 움직이는 미로 탈출 (0) | 2025.03.17 |
[Algorithm]Baekjoon 16562번 :: 친구비 (0) | 2025.03.17 |
[Algorithm]Baekjoon 6236번 :: 용돈 관리 (0) | 2025.03.17 |