#include <bits/stdc++.h>
using namespace std;
inline int readInt() {
int x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9'){
x = (x << 3) + (x << 1) + ch - '0';
ch = getchar();
}
return x;
}
int X[10000000], Y[10000000];
bool in(int a, int b){
/// if b is under a, return true
int x1 = X[a];
int x2 = X[b];
int y1 = Y[a];
int y2 = Y[b];
return abs(x1 - x2) <= y1 - y2;
}
int main(){
//freopen("i.txt.txt","r",stdin);
int n = readInt();
for(int i = 0; i < n; i++) {
X[i] = readInt();
Y[i] = readInt();
// write code here
}
// write code here
//for(int i = 0;i < n;i++){
//printf("%d %d\n",X[i],Y[i]);
//}
stack<int> s;
if(in(2,3)){
//printf("yes");
}
for(int i = 0;i < n;i++){
if(s.empty()){
s.push(i);
continue;
}
else if(in(s.top(),i)){
continue;
}
else if(in(i,s.top())){
while(!s.empty() && in(i,s.top())){
s.pop();
}
s.push(i);
}
else{
s.push(i);
}
}
printf("%d",s.size());
return 0;
}
Compilation message
lightningrod.cpp: In function 'int main()':
lightningrod.cpp:64:22: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::stack<int>::size_type {aka long unsigned int}' [-Wformat=]
printf("%d",s.size());
~~~~~~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1245 ms |
228832 KB |
Output is correct |
2 |
Correct |
1221 ms |
228144 KB |
Output is correct |
3 |
Correct |
1228 ms |
222012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
256 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
256 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
456 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
256 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
456 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
45 ms |
5492 KB |
Output is correct |
15 |
Correct |
39 ms |
5240 KB |
Output is correct |
16 |
Correct |
42 ms |
4856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1227 ms |
200320 KB |
Output is correct |
2 |
Correct |
1089 ms |
200216 KB |
Output is correct |
3 |
Correct |
1076 ms |
195456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1245 ms |
228832 KB |
Output is correct |
2 |
Correct |
1221 ms |
228144 KB |
Output is correct |
3 |
Correct |
1228 ms |
222012 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
456 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
45 ms |
5492 KB |
Output is correct |
18 |
Correct |
39 ms |
5240 KB |
Output is correct |
19 |
Correct |
42 ms |
4856 KB |
Output is correct |
20 |
Correct |
1227 ms |
200320 KB |
Output is correct |
21 |
Correct |
1089 ms |
200216 KB |
Output is correct |
22 |
Correct |
1076 ms |
195456 KB |
Output is correct |
23 |
Correct |
1839 ms |
246580 KB |
Output is correct |
24 |
Correct |
1645 ms |
228064 KB |
Output is correct |
25 |
Correct |
1387 ms |
210904 KB |
Output is correct |