제출 #83434

#제출 시각아이디문제언어결과실행 시간메모리
83434tjdgus4384곡선 자르기 (KOI17_cut)C++14
35 / 100
37 ms5288 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...