Submission #896846

# Submission time Handle Problem Language Result Execution time Memory
896846 2024-01-02T09:38:47 Z danikoynov Hamburg Steak (JOI20_hamburg) C++14
6 / 100
331 ms 23488 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 2e5 + 10;
struct event
{
    int tim, type, idx;

    event(int _tim = 0, int _type = 0, int _idx = 0)
    {
        tim = _tim;
        type = _type;
        idx = _idx;
    }

    bool operator < (const event &e) const
    {
        if (tim != e.tim)
            return tim < e.tim;
        return type > e.type;
    }

};

struct point
{
    int x, y;

    point(int _x = 0, int _y = 0)
    {
        x = _x;
        y = _y;
    }

    void input()
    {
        cin >> x >> y;
    }
};

struct rectangle
{
    point A, B;

    rectangle()
    {
        A = point();
        B = point();
    }
    void input()
    {
        A.input();
        B.input();
    }
} r[maxn];

int n, k;
void input()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i ++)
        r[i].input();
}

vector < int > pos_x, pos_y;
void get_x()
{
    vector < event > events;
    for (int i = 1; i <= n; i ++)
    {
        events.push_back(event(r[i].A.x, 1, i));
        events.push_back(event(r[i].B.x, -1, i));
    }

    sort(events.begin(), events.end());

    int last = -1e9, bef = -1;
    for (int i = 0; i < 2 * n; i ++)
    {
        ///cout << events[i].type << " " << r[events[i].idx].A.x - last  << endl;
        if (events[i].type == -1 && r[events[i].idx].A.x > last && bef != -1)
        {
            last = events[bef].tim;
            pos_x.push_back(events[bef].tim);
            bef = -1;
        }
        if (events[i].type == 1)
            bef = i;
        /**if (events[i].type == 1 && (events[i + 1].type == -1 && r[events[i + 1].idx].A.x > last))
        {
            last = events[i].tim;
            pos_x.push_back(events[i].tim);
        }*/
    }
}

void get_y()
{
    vector < event > events;
    for (int i = 1; i <= n; i ++)
    {
        events.push_back(event(r[i].A.y, 1, i));
        events.push_back(event(r[i].B.y, -1, i));
    }

    sort(events.begin(), events.end());

    int last = -1e9, bef = -1;
    for (int i = 0; i < 2 * n; i ++)
    {
        ///cout << events[i].type << " " << r[events[i].idy].A.y - last  << endl;
        if (events[i].type == -1 && r[events[i].idx].A.y > last && bef != -1)
        {
            last = events[bef].tim;
            pos_y.push_back(events[bef].tim);
            bef = -1;
        }
        if (events[i].type == 1)
            bef = i;
        /**if (events[i].type == 1 && (events[i + 1].type == -1 && r[events[i + 1].idy].A.y > last))
        {
            last = events[i].tim;
            pos_y.push_back(events[i].tim);
        }*/
    }
}
const int maxk = 5;

const int maxs = maxk * maxk;
pair < int, int > skew[maxs];
int m;
bitset < maxn > skew_set[maxs];

bool inside(pair < int, int > cur, rectangle rec)
{
    if (cur.first >= rec.A.x && cur.first <= rec.B.x &&
            cur.second >= rec.A.y && cur.second <= rec.B.y)
        return true;
    return false;
}

void match_pairs()
{
    ///cout << pos_x.size() << " : " << pos_y.size() << endl;
    for (int x : pos_x)
        for (int y : pos_y)
            skew[++ m] = {x, y};

    for (int i = 1; i <= m; i ++)
        for (int j = 1; j <= n; j ++)
            skew_set[i][j] = inside(skew[i], r[j]);

}

void find_skewers()
{
    if (k == 1)
    {
        assert(m == 1);
        cout << skew[1].first << " " << skew[1].second << endl;
        return;
    }

    if (k == 2)
    {
        ///cout << pos_x.size() << " : " << pos_y.size() << endl;
        for (int i = 1; i <= m; i ++)
            for (int j = i; j <= m; j ++)
            {
                if ((skew_set[i] | skew_set[j]).count() == n)
                {
                    cout << skew[i].first << " " << skew[i].second << endl;
                    cout << skew[j].first << " " << skew[j].second << endl;
                    return;
                }
            }

        ///assert(false);
    }
}
void solve()
{
    input();
    get_x();
    get_y();
    match_pairs();
    find_skewers();
}

int main()
{
    ///freopen("test.txt", "r", stdin);
    solve();
    return 0;
}


Compilation message

hamburg.cpp: In function 'void find_skewers()':
hamburg.cpp:188:57: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  188 |                 if ((skew_set[i] | skew_set[j]).count() == n)
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3932 KB Output is correct
2 Correct 4 ms 3932 KB Output is correct
3 Correct 4 ms 3932 KB Output is correct
4 Correct 4 ms 3932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3932 KB Output is correct
2 Correct 4 ms 3932 KB Output is correct
3 Correct 4 ms 4020 KB Output is correct
4 Correct 4 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 3928 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 3928 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3932 KB Output is correct
2 Correct 4 ms 3932 KB Output is correct
3 Correct 4 ms 3932 KB Output is correct
4 Correct 4 ms 3932 KB Output is correct
5 Correct 295 ms 16148 KB Output is correct
6 Correct 293 ms 15376 KB Output is correct
7 Correct 286 ms 14784 KB Output is correct
8 Correct 297 ms 16236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3932 KB Output is correct
2 Correct 4 ms 3932 KB Output is correct
3 Correct 4 ms 4020 KB Output is correct
4 Correct 4 ms 4188 KB Output is correct
5 Correct 306 ms 22952 KB Output is correct
6 Correct 318 ms 23488 KB Output is correct
7 Correct 322 ms 22688 KB Output is correct
8 Correct 331 ms 23376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 3928 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 3928 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -