[BOJ] 1637 날카로운 눈

Time Lapse :46min 56sec

1637.cpp

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
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
const ll INF = 1LL<<32;
ll arr[20002][3], n;
ll getCnt(long long m) {
ll ret = 0;
for(int i = 0; i < n; i++)
if(arr[i][0] <= m)
ret += (min(m,arr[i][2]) - arr[i][0]) / arr[i][1] + 1;
return ret;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%lld %lld %lld", &arr[i][0], &arr[i][2], &arr[i][1]);
ll l = 0, r = INF, m;
while (l < r) {
m = (l + r) / 2;
if (getCnt(m) & 1)
r = m;
else
l = m + 1;
}
if (l == INF)
printf("NOTHING");
else
printf("%lld %lld", l, getCnt(l) - getCnt(l - 1));
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/09/10/PS/BOJ/1637/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.