fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
Codeforces Round 1050-B (Div. 4) Lasers
최초 업로드: 2025-09-13 17:19:32
최근 수정 시간: 2025-09-13 17:19:32
게시자: rlatjwls3333
카테고리: Codeforces
조회수: 147
# B. Lasers [문제 링크](https://codeforces.com/contest/2148/problem/B) ## Problem Statement There is a 2D-coordinate plane that ranges from $(0, 0)$ to $(x, y)$. You are located at $(0, 0)$ and want to head to $(x, y)$. However, there are $n$ horizontal lasers, with the $i$-th laser continuously spanning $(0, a_i)$ to $(x, a_i)$. Additionally, there are also $m$ vertical lasers, with the $i$-th laser continuously spanning $(b_i, 0)$ to $(b_i, y)$. You may move in any direction to reach $(x, y)$, but your movement must be a continuous curve that lies inside the plane. Every time you cross a vertical or a horizontal laser, it counts as one crossing. Particularly, if you pass through an intersection point between two lasers, it counts as **two crossings**. For example, if $x = y = 2$, $n = m = 1$, $a = [1]$, $b = [1]$, the movement can be as follows: <center> <img src="https://espresso.codeforces.com/44cd14d5698957fd058be07680bad092035229a0.png" width="300"/> </center> Minimum crossings = 2 (must cross $x=1$ and $y=1$ once each). ## Input The first line contains $t$ ($1 \leq t \leq 10^4$) — the number of test cases. The first line of each test case contains four integers $n, m, x, y$ ($1 \leq n, m \leq 2 \cdot 10^5$, $2 \leq x, y \leq 10^9$). The following line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 < a_i < y$) — the y-coordinates of the horizontal lasers. It is guaranteed that $a_i > a_{i-1}$ for all $i > 1$. The following line contains $m$ integers $b_1, b_2, \ldots, b_m$ ($0 < b_i < x$) — the x-coordinates of the vertical lasers. It is guaranteed that $b_i > b_{i-1}$ for all $i > 1$. It is guaranteed that the sum of $n$ and $m$ over all test cases does not exceed $2 \cdot 10^5$. ## Output For each test case, output the minimum number of crossings necessary to reach $(x, y)$. ## 풀이 n+m을 출력하면 되는 문제입니다. ``` c++ #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--) { int n, m, x, y; cin >> n >> m >> x >> y; int tmp; for(int i=0;i<n;i++) cin >> tmp; for(int i=0;i<m;i++) cin >> tmp; cout << n+m << '\n'; } } ```