답안 #1002822

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1002822 2024-06-19T20:09:32 Z hyakup Izvanzemaljci (COI21_izvanzemaljci) C++17
5 / 100
55 ms 3160 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define bug(x) cout << #x << " " << x << endl;
#define pii pair<int, int> 


const int inf = 1e9 + 10; 

void solve1( vector<pii>& v ){
    int x1 = inf, x2 = -inf, y1 = inf, y2 = -inf; 
    for( auto [x, y] : v ){
        x1 = min( x1, x ); 
        x2 = max( x2, x ); 
        y1 = min( y1, y ); 
        y2 = max( y2, y ); 
    }

    int tam = max( x2 - x1, y2 - y1 ); 
    tam = max( tam, 1 );
    cout << x1 << " " << y1 << " " << tam << endl;
}

struct rect{
    int x, y, tam; rect( int x = 0, int y = 0, int tam = inf ) :x(x), y(y), tam(tam)  {}
}; 

void solve2( vector<pii>& v ){
    

    sort( v.begin(), v.end(), [&]( pii a, pii b ){
        if( a.first == b.first ) return a.second < b.second; 
        return a.first < b.first; 
    }); // ordena por x;    
    vector<rect> resp( v.size() ); 

    if( v.size() == 2 ){
        cout << v[0].first - 1 << " " << v[0].first - 1 << " " << 1; 
        cout << v[1].first << " " << v[1].first << " " << 1; 
        return; 
    }

    int x1 = inf, x2 = -inf, y1 = inf, y2 = -inf; 
    for( int i = 0; i < v.size(); i++ ){
        auto [x, y] = v[i]; 
        x1 = min( x1, x ); 
        x2 = max( x2, x ); 
        y1 = min( y1, y ); 
        y2 = max( y2, y ); 
        if( v[i + 1].first != v[i].first ) resp[i] = rect( x2 - max( x2 - x1, y2 - y1 ), y2 - max( x2 - x1, y2 - y1 ), max( x2 - x1, y2 - y1 ) );
        else if( i > 0 ) resp[i] = resp[i - 1]; 
        resp[i].tam = max( resp[i].tam, 1 ); 
    }

    x1 = inf, x2 = -inf, y1 = inf, y2 = -inf;   

    rect a( 0,0, inf ), b( 0, 0, inf ); 

    for( int i = v.size() - 1; i > 0; i-- ){
        auto [x, y] = v[i]; 
        x1 = min( x1, x ); 
        x2 = max( x2, x ); 
        y1 = min( y1, y ); 
        y2 = max( y2, y ); 
        rect cur( x1, y1, max( x2 - x1, y2 - y1 ) );

        if( v[i - 1].first != v[i].first && max( cur.tam, resp[i - 1].tam ) < max( a.tam, b.tam ) ){
            a = cur; 
            b = resp[i - 1]; 
            a.tam = max( a.tam, 1 ); 
            b.tam = max( b.tam, 1 ); 
        }
    }
    /////////////////////////////////////////////////////////////////////////////////////////
    sort( v.begin(), v.end(), [&]( pii a, pii b ){
        return a.second < b.second; 
    }); // ordena por y;    
    resp.clear(); 
    resp.resize(v.size()); 

    x1 = inf, x2 = -inf, y1 = inf, y2 = -inf; 
    for( int i = 0; i < v.size(); i++ ){
        auto [x, y] = v[i]; 
        x1 = min( x1, x ); 
        x2 = max( x2, x ); 
        y1 = min( y1, y ); 
        y2 = max( y2, y ); 
        if( v[i].second != v[i + 1].second ) resp[i] = rect( x2 - max( x2 - x1, y2 - y1 ), y2 - max( x2 - x1, y2 - y1 ), max( x2 - x1, y2 - y1 ) );
        else if( i > 0 ) resp[i] = resp[i - 1]; 
        resp[i].tam = max( resp[i].tam, 1 ); 
    }

    x1 = inf, x2 = -inf, y1 = inf, y2 = -inf;   

    for( int i = v.size() - 1; i > 0; i-- ){

        auto [x, y] = v[i]; 
        x1 = min( x1, x ); 
        x2 = max( x2, x ); 
        y1 = min( y1, y ); 
        y2 = max( y2, y ); 
        rect cur( x1, y1, max( x2 - x1, y2 - y1 ) );

        if( v[i].second != v[i - 1].second && max( cur.tam, resp[i - 1].tam ) < max( a.tam, b.tam ) ){
            a = cur; 
            b = resp[i - 1]; 
            a.tam = max( a.tam, 1 ); 
            b.tam = max( b.tam, 1 ); 
        }
    }
    cout << a.x << " " << a.y << " " << a.tam << endl;
    cout << b.x << " " << b.y << " " << b.tam << endl;
}

int main(){
    int n, k; cin >> n >> k; 
    vector<pii> v(n); 
    for( int i = 0; i < n; i++ ) cin >> v[i].first >> v[i].second; 
    if( k == 1 ) solve1(v); 
    else if( k == 2 ) solve2( v ); 
}

Compilation message

izvanzemaljci.cpp: In function 'void solve2(std::vector<std::pair<int, int> >&)':
izvanzemaljci.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for( int i = 0; i < v.size(); i++ ){
      |                     ~~^~~~~~~~~~
izvanzemaljci.cpp:82:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for( int i = 0; i < v.size(); i++ ){
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 52 ms 3160 KB Output is correct
8 Correct 55 ms 3152 KB Output is correct
9 Correct 51 ms 3104 KB Output is correct
10 Correct 53 ms 2996 KB Output is correct
11 Correct 51 ms 3140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 604 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -