답안 #83435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83435 2018-11-07T14:58:33 Z tjdgus4384 곡선 자르기 (KOI17_cut) C++14
100 / 100
407 ms 249392 KB
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
vector<pair<int, int> > v;
int x[1000001], y[1000001];

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 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 456 KB Output is correct
5 Correct 2 ms 456 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 616 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 456 KB Output is correct
5 Correct 2 ms 456 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 616 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 3 ms 636 KB Output is correct
18 Correct 4 ms 636 KB Output is correct
19 Correct 7 ms 660 KB Output is correct
20 Correct 5 ms 660 KB Output is correct
21 Correct 6 ms 660 KB Output is correct
22 Correct 5 ms 660 KB Output is correct
23 Correct 5 ms 660 KB Output is correct
24 Correct 5 ms 660 KB Output is correct
25 Correct 6 ms 660 KB Output is correct
26 Correct 5 ms 660 KB Output is correct
27 Correct 6 ms 660 KB Output is correct
28 Correct 5 ms 660 KB Output is correct
29 Correct 5 ms 660 KB Output is correct
30 Correct 9 ms 660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 456 KB Output is correct
5 Correct 2 ms 456 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 616 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 3 ms 636 KB Output is correct
18 Correct 4 ms 636 KB Output is correct
19 Correct 7 ms 660 KB Output is correct
20 Correct 5 ms 660 KB Output is correct
21 Correct 6 ms 660 KB Output is correct
22 Correct 5 ms 660 KB Output is correct
23 Correct 5 ms 660 KB Output is correct
24 Correct 5 ms 660 KB Output is correct
25 Correct 6 ms 660 KB Output is correct
26 Correct 5 ms 660 KB Output is correct
27 Correct 6 ms 660 KB Output is correct
28 Correct 5 ms 660 KB Output is correct
29 Correct 5 ms 660 KB Output is correct
30 Correct 9 ms 660 KB Output is correct
31 Correct 100 ms 4524 KB Output is correct
32 Correct 278 ms 27056 KB Output is correct
33 Correct 62 ms 27056 KB Output is correct
34 Correct 242 ms 45500 KB Output is correct
35 Correct 359 ms 67036 KB Output is correct
36 Correct 338 ms 87124 KB Output is correct
37 Correct 382 ms 107528 KB Output is correct
38 Correct 343 ms 127268 KB Output is correct
39 Correct 329 ms 147584 KB Output is correct
40 Correct 407 ms 165276 KB Output is correct
41 Correct 372 ms 182804 KB Output is correct
42 Correct 326 ms 202516 KB Output is correct
43 Correct 326 ms 218548 KB Output is correct
44 Correct 329 ms 234432 KB Output is correct
45 Correct 327 ms 249392 KB Output is correct