답안 #400175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400175 2021-05-07T13:38:54 Z mathking1021 곡선 자르기 (KOI17_cut) C++17
0 / 100
2 ms 332 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <algorithm>
#define PLL pair<ll, ll>
#define F first
#define S second

using namespace std;
typedef long long ll;

const ll INF = 4e18;
ll n;
ll a[1000005];
ll b[1000005];

vector<ll> ve1, ve2;
vector<PLL> ve;
stack<ll> st1, st2, st3;

ll ans1, ans2;

int main()
{
    freopen("input.txt", "r", stdin);
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld%lld", &a[i], &b[i]);
    }
    for(ll i = 1; i <= n; i++)
    {
        if(b[i - 1] < 0 && b[i % n] > 0) ve1.push_back(a[i]);
        else if(b[i - 1] > 0 && b[i % n] < 0)
        {
            if(ve1.empty()) ve1.push_back(INF);
            ve2.push_back(a[i % n]);
        }
    }
    if(ve1[0] == INF) ve1[0] = ve1.back(), ve1.pop_back();
    for(ll i = 0; i < ve1.size(); i++)
    {
        ve.push_back(make_pair(ve1[i], ve2[i]));
    }
    for(ll i = 0; i < ve.size(); i++)
    {
        if(ve[i].F > ve[i].S) swap(ve[i].F, ve[i].S);
    }
    sort(ve.begin(), ve.end());
    for(ll i = 0; i < ve.size(); i++)
    {
        while(!st1.empty() && st2.top() < ve[i].F)
        {
            if(st3.top() == 0) ans1++;
            st1.pop(), st2.pop(), st3.pop();
        }
        if(!st3.empty())
        {
            st3.pop(), st3.push(1);
        }
        st1.push(ve[i].F), st2.push(ve[i].S), st3.push(0);
    }
    while(!st1.empty())
    {
        if(st3.top() == 0) ans1++;
        st1.pop(), st2.pop(), st3.pop();
    }
    for(ll i = 0; i < ve.size(); i++)
    {
        while(!st1.empty() && st2.top() < ve[i].F)
        {
            if(st3.top() == 0) ans2++;
            st1.pop(), st2.pop(), st3.pop();
        }
        if(!st3.empty())
        {
            st1.push(ve[i].F), st2.push(ve[i].S), st3.push(1);
        }
        else
        {
            st1.push(ve[i].F), st2.push(ve[i].S), st3.push(0);
        }
    }
    while(!st1.empty())
    {
        if(st3.top() == 0) ans2++;
        st1.pop(), st2.pop(), st3.pop();
    }
    printf("%lld %lld\n", ans2, ans1);
    return 0;
}

Compilation message

cut.cpp: In function 'int main()':
cut.cpp:42:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(ll i = 0; i < ve1.size(); i++)
      |                   ~~^~~~~~~~~~~~
cut.cpp:46:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(ll i = 0; i < ve.size(); i++)
      |                   ~~^~~~~~~~~~~
cut.cpp:51:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(ll i = 0; i < ve.size(); i++)
      |                   ~~^~~~~~~~~~~
cut.cpp:69:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for(ll i = 0; i < ve.size(); i++)
      |                   ~~^~~~~~~~~~~
cut.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
cut.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |     scanf("%lld", &n);
      |     ~~~~~^~~~~~~~~~~~
cut.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |         scanf("%lld%lld", &a[i], &b[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -