fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
Codeforces Round 1050-C (Div. 4) Pacer
최초 업로드: 2025-09-13 17:30:50
최근 수정 시간: 2025-09-13 17:30:50
게시자: rlatjwls3333
카테고리: Codeforces
조회수: 39
# C. Pacer [문제 링크](https://codeforces.com/contest/2148/problem/C) ## Problem Statement *The FitnessGram Pacer Test is a multistage aerobic capacity test that progressively gets more difficult as it continues. The 20 meter pacer test will begin in 30 seconds. Line up at the start. A single lap should be completed every time you hear this sound. Ding! Remember to run in a straight line and run as long as possible. The test will begin on the word start. On your mark. Get ready!...* Farmer John is running the FitnessGram Pacer Test! Farmer John takes **one minute** to run to the other side of the gym. Therefore, at the start of each minute, FJ can choose to either run to the other side of the gym or stay in place. If he chooses to run to the other side of the gym, he gains **one point**. FJ will run the Pacer Test until the start of the $m$-th minute. Initially (at the start of the $0$-th minute), FJ is at the starting side of the gym, which we will denote as side $0$. The opposite side of the gym is denoted side $1$. The pacer test audio plays $n$ times. At the start of the $a_i$-th minute, FJ must be at the $b_i$-th side of the gym. What is the maximum number of points FJ can acquire while ensuring that he meets the audio's requirements? ## Input The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. The first line of each test case contains two integers $n$ and $m$ ($1 \leq n \leq 2 \cdot 10^5, n \leq m \leq 10^9$) — the number of requirements and the number of total minutes. The following $n$ lines contain two integers $a_i$ and $b_i$ ($1 \leq a_i \leq m, b_i \in \{0,1\}$) — the $i$-th requirement by the audio. It is guaranteed that $a_i > a_{i-1}$ for all $i > 1$. It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. ## Output For each test case, output the maximum number of points that FJ can acquire. ## 풀이 시간이 짝수 시간 차이가 나는 지의 여부와 같은 위치에 있는 지의 여부가 동일하면 시간 차이 만큼의 점수가, 그렇지 않으면 시간 차이 -1의 점수가 증가한다. ``` 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; cin >> n >> m; int point=0, lastA=0, pos=0; while(n--) { int a, b; cin >> a >> b; if(((a-lastA)%2==0) == (pos==b)) point += a-lastA; else point += a-lastA-1; lastA = a; pos = b; } cout << point + (m-lastA) << '\n'; } } ```