#include<cstdio>
#include<vector>
#include<algorithm>
int x[100001], y[100001];
using namespace std;
vector<pair<int, int> > v;
int main()
{
int n;
scanf("%d", &n);
for(int i = 0;i < n;i++)
{
scanf("%d %d", &x[i], &y[i]);
}
int state = 0, last, st = x[0];
bool change = false;
for(int i = 1;i < n;i++)
{
if(y[i - 1] < 0 && y[i] > 0) {last = x[i];state = 1;}
else if(state && y[i - 1] > 0 && y[i] < 0)
{
state = 0;
v.push_back({min(last, x[i]), max(last, x[i])});
}
else if(y[i - 1] > 0 && y[i] < 0) {st = x[i]; change = true;}
}
if(state)
{
v.push_back({min(last, st), max(last, st)});
}
else if(change)
{
v.push_back({min(x[0], st), max(x[0], st)});
}
sort(v.begin(), v.end());
int ans1 = 0, ans2 = 0;
int maxx = -2e9;
for(int i = 0;i < v.size();i++)
{
if(maxx < v[i].first) ans1++;
maxx = max(maxx, v[i].second);
if(i == v.size() - 1 || v[i + 1].first > v[i].second) ans2++;
}
printf("%d %d", ans1, ans2);
return 0;
}
Compilation message
cut.cpp: In function 'int main()':
cut.cpp:39:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i < v.size();i++)
~~^~~~~~~~~~
cut.cpp:43:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(i == v.size() - 1 || v[i + 1].first > v[i].second) ans2++;
~~^~~~~~~~~~~~~~~
cut.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
cut.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &x[i], &y[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
3 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
636 KB |
Output is correct |
10 |
Correct |
3 ms |
636 KB |
Output is correct |
11 |
Correct |
2 ms |
636 KB |
Output is correct |
12 |
Correct |
2 ms |
636 KB |
Output is correct |
13 |
Correct |
2 ms |
808 KB |
Output is correct |
14 |
Correct |
2 ms |
808 KB |
Output is correct |
15 |
Correct |
2 ms |
808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
3 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
636 KB |
Output is correct |
10 |
Correct |
3 ms |
636 KB |
Output is correct |
11 |
Correct |
2 ms |
636 KB |
Output is correct |
12 |
Correct |
2 ms |
636 KB |
Output is correct |
13 |
Correct |
2 ms |
808 KB |
Output is correct |
14 |
Correct |
2 ms |
808 KB |
Output is correct |
15 |
Correct |
2 ms |
808 KB |
Output is correct |
16 |
Correct |
2 ms |
808 KB |
Output is correct |
17 |
Correct |
2 ms |
808 KB |
Output is correct |
18 |
Correct |
3 ms |
808 KB |
Output is correct |
19 |
Correct |
5 ms |
1008 KB |
Output is correct |
20 |
Correct |
6 ms |
1188 KB |
Output is correct |
21 |
Correct |
5 ms |
1188 KB |
Output is correct |
22 |
Correct |
7 ms |
1188 KB |
Output is correct |
23 |
Correct |
6 ms |
1188 KB |
Output is correct |
24 |
Correct |
8 ms |
1188 KB |
Output is correct |
25 |
Correct |
6 ms |
1436 KB |
Output is correct |
26 |
Correct |
6 ms |
1668 KB |
Output is correct |
27 |
Correct |
7 ms |
1740 KB |
Output is correct |
28 |
Correct |
6 ms |
2008 KB |
Output is correct |
29 |
Correct |
6 ms |
2184 KB |
Output is correct |
30 |
Correct |
6 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
3 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
636 KB |
Output is correct |
10 |
Correct |
3 ms |
636 KB |
Output is correct |
11 |
Correct |
2 ms |
636 KB |
Output is correct |
12 |
Correct |
2 ms |
636 KB |
Output is correct |
13 |
Correct |
2 ms |
808 KB |
Output is correct |
14 |
Correct |
2 ms |
808 KB |
Output is correct |
15 |
Correct |
2 ms |
808 KB |
Output is correct |
16 |
Correct |
2 ms |
808 KB |
Output is correct |
17 |
Correct |
2 ms |
808 KB |
Output is correct |
18 |
Correct |
3 ms |
808 KB |
Output is correct |
19 |
Correct |
5 ms |
1008 KB |
Output is correct |
20 |
Correct |
6 ms |
1188 KB |
Output is correct |
21 |
Correct |
5 ms |
1188 KB |
Output is correct |
22 |
Correct |
7 ms |
1188 KB |
Output is correct |
23 |
Correct |
6 ms |
1188 KB |
Output is correct |
24 |
Correct |
8 ms |
1188 KB |
Output is correct |
25 |
Correct |
6 ms |
1436 KB |
Output is correct |
26 |
Correct |
6 ms |
1668 KB |
Output is correct |
27 |
Correct |
7 ms |
1740 KB |
Output is correct |
28 |
Correct |
6 ms |
2008 KB |
Output is correct |
29 |
Correct |
6 ms |
2184 KB |
Output is correct |
30 |
Correct |
6 ms |
2396 KB |
Output is correct |
31 |
Execution timed out |
37 ms |
5288 KB |
Time limit exceeded (wall clock) |
32 |
Halted |
0 ms |
0 KB |
- |