-
https://www.acmicpc.net/problem/2002
2002번: 추월
입력은 총 2N+1개의 줄로 이루어져 있다. 첫 줄에는 차의 대수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄부터 N개의 줄에는 대근이가 적은 차량 번호 목록이 주어지고, N+2째 줄부터 N개의 줄에는 영식이
www.acmicpc.net
터널에서 나온 차량번호를 기준으로 볼때, 현재 차량보다 더 늦게나온 차량이 터널에 더 먼저 진입한 경우를 확인한다.
터널에 나온 시점을 map<string, int>로 관리하자.
#include <bits/stdc++.h>using namespace std;#ifdef ONLINE_JUDGEconstexpr bool local = false;#elseconstexpr bool local = true;#endifusing ll = long long;using pi = pair<ll, ll>;int n, ans;map<string, int> s, e;int main(void) {if (!local) ios_base::sync_with_stdio(0), cin.tie(0);cin >> n;int i, j;for (i = 0; i < n; i++) {string str;cin >> str;s[str] = i;}vector<string> v(n);for (i = 0; i < n; i++) cin >> v[i], e[v[i]] = i;for (i = 0; i < n; i++) {for (j = i + 1; j < n; j++) {if (s[v[i]] > s[v[j]]) {ans++;break;}}}cout << ans;return 0;}
'BOJ' 카테고리의 다른 글
[7453] 합이 0인 네 정수 (0) 2022.03.12 [2281] 데스노트 (0) 2022.03.12 [1662] 압축 (0) 2022.03.09 [1256] 사전 (0) 2022.03.06 [15684] 사다리 조작 (0) 2022.03.06