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
- Operating System
- DP
- 오퍼레이팅시스템
- 개발
- coding
- 알고리즘
- 정석
- 그래프
- 스택
- 컴공
- 코테
- Computer science
- 구현
- 컴퓨터공학과
- 자료구조
- c++
- 백준
- 북리뷰
- 브루트포스
- cs
- 정석학술정보관
- Stack
- 오에스
- 문제풀이
- vector
- 코딩
- 컴공과
- bfs
- 너비우선탐색
Archives
- Today
- Total
Little Jay
[C++] 백준 20291번 - 파일 정리 본문
substring과 map을 활용한 문제
map은 자료를 저장할때 red-black tree 구조로 구현이 되어있기 때문에 자동 정렬이 된다.
이는 int형 뿐만 아니라 string 형태에서도 char에 따라서 정렬을 한다.
'ab' < 'b' 이기 때문에 iterator.begin()은 'ab'를 가리키고 있을 것이다.
이러한 점만 고려하면 쉽게 풀 수 있는 문제이다.
물론 pair를 사용해서 sort를 쓸 수도 있지만 map이라는 편리한 기능이 있으니 이를 사용하자
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int n;
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
vector<vector<int>> v;
v.resize(n);
vector<int> line_max;
int m = -1;
for (int i = 0; i < n; i++) {
int x; cin >> x; v[i].push_back(x);
m = max(m, x);
}
line_max.push_back(m);
int ans = 0;
for (int i = 1; i < n; i++) {
int m = -1;
for (int j = 0; j < n; j++) {
int x; cin >> x;
v[i].push_back(x);
m = max(m, x);
}
line_max.push_back(m);
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < n; j++) {
if (v[i][j] > line_max[i - 1]) {
cout << v[i][j] << endl;
return 0;
}
}
}
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 11660번 - 구간 합 구하기5 (0) | 2022.11.29 |
---|---|
[C++] 백준 2670 - 연속부분최대곱(with setprecision) (0) | 2022.11.28 |
[C++] 백준 14938번 - 서강그라운드 (0) | 2022.09.24 |
[C++] 백준 11725번 - 트리의 부모 찾기 (0) | 2022.09.22 |
[C++] 백준 14675번 - 단절점과 단절선 (1) | 2022.09.19 |
Comments