Submission #1080774

# Submission time Handle Problem Language Result Execution time Memory
1080774 2024-08-29T14:01:07 Z abouton Tiles (BOI24_tiles) C++17
71 / 100
79 ms 12736 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

struct ar
{
    int yD, yF, x;
    bool typ;
    bool operator<(const ar &autre) const
    {
        if (x == autre.x) return yD < autre.yD;
        return x < autre.x;
    }
};

struct inter
{
    int y1, y2;
    bool par;
    bool operator<(const inter &autre) const
    {
        return y1 < autre.y1;
    }
};
int nbI;
vector<ar> aretes;
set<inter> cur;
int N, M, maxi;
int nbA;
int nb[2];

void aj(int y1, int y2, int x)
{
    auto it = cur.lower_bound({y2,0,0});
    assert (it != cur.begin());
    assert(it != cur.end());
    auto prec = *prev(it);
    auto suiv = *it;
    if (y1 == prec.y2 && (x%2) == prec.par)
    {
        y1 = prec.y1;
        nb[prec.par]--;
        nbI -= ((prec.y1+prec.y2)%2);
        cur.erase(prec);
        if ((prec.par+x)%2) nb[(x+1)%2]++;
    }
    if (y2==suiv.y1 && (x%2) == suiv.par)
    {
        y2 = suiv.y2;
        nb[suiv.par]--;
        nbI -= ((suiv.y1+suiv.y2)%2);
        cur.erase(suiv);
        if ((suiv.par+x)%2) nb[(x+1)%2]++;
    }
    nb[(bool)(x%2)]++;
    cur.insert({y1,y2,(bool)(x%2)});
    nbI += ((y1+y2)%2);
}

void ret(int y1,int y2, int x)
{
    auto it = cur.upper_bound({y1,0,0});
    auto mec = *prev(it);
    //cout << y1 << ' ' << y2 << ' ' << mec.y1 << ' ' << mec.y2 << '\n';
    //cout << (*it).y1 << ' ' << (*it).y2 << '\n';
    //assert (mec.y1 <= y1 && mec.y2 >= y2);
    //cout << "alors " << y1 << ' ' << y2 << ' ' << mec.y1 << ' ' << mec.y2 << '\n';
    if (mec.y2 < y2)
    {
        nb[(x+1)%2] ++;
        cout << maxi;
        exit(0);
    }
    if ((mec.par+x)%2) nb[(x+1)%2] ++;
    nb[mec.par]--;
    nbI -= ((mec.y1+mec.y2)%2);
    cur.erase(mec);

    if (y1 > mec.y1)
    {

        nbI += ((mec.y1+y1)%2);
        //cout << mec.y1 << ' ' <<y1<<'\n';
        cur.insert({mec.y1, y1, (bool)(x%2)});
        //cout << 'a';
        //for (auto i : cur) cout << i.y1 <<i.y2<<' ';
        nb[(bool)(x%2)]++;
    }
    if (y2 < mec.y2)
    {        
        nbI += ((mec.y2+y2)%2);
        cur.insert({y2, mec.y2, (bool)(x%2)});
        nb[(bool)(x%2)]++;
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin >> N >> M;
    maxi = 0;
    bool sens = 0;
    int precX, precY, x0, y0;
    cin >> precX >> precY;
    x0 = precX; y0 = precY;
    for (int i = 0; i < N; i ++)
    {
        int x, y;
        if (i<N-1) cin >> x >> y;
        else
        {
            x = x0; y = y0;
        }
        if (x == precX)
        {
            aretes.push_back({precY, y, x, 0});
        }
        if (x == 0 && precX == 0) {sens = !(y>precY);}
        precX = x; precY = y;
    }
    nbA = aretes.size();
    for (int i = 0; i < nbA; i ++)
    {
        aretes[i].typ = sens ^ (aretes[i].yF > aretes[i].yD);
        //cout << (int) sens << (int)(aretes[i].yF>aretes[i].yD);
        if (aretes[i].yF < aretes[i].yD) swap(aretes[i].yD, aretes[i].yF);
    }

    //for (auto i : aretes)
    //{
    //    cout << i.yD << ' ' << i.yF << ' ' << i.x << ' ' << (int)i.typ << '\n';
    //}

    sort(aretes.begin(), aretes.end());
    cur.insert({-1, -1,0});
    cur.insert({1000000001, 1000000001, 0});
    for (int i = 0; i < nbA; i ++)
    {
        if (nb[(aretes[i].x+1)%2]==0)
            maxi = aretes[i].x;
        else if (nb[(aretes[i].x)%2]==0)
            maxi = aretes[i].x-1;
            
        if (aretes[i].typ) aj(aretes[i].yD, aretes[i].yF, aretes[i].x);
        else ret(aretes[i].yD, aretes[i].yF, aretes[i].x);

        /*cout << "nouv : " << aretes[i].yD << ' ' << aretes[i].yF << ' ' << aretes[i].x << '\n';
        for (auto truc : cur)
        {
            cout << truc.y1 << ' ' << truc.y2 << " et " << nbI << '\n';
        }
        cout << '\n';*/

        if (i == nbA-1 || aretes[i+1].x > aretes[i].x)
        {
            //cout << nb[0] << ' ' << nb[1] << '\n';
            if (nbI!=0)
            {
                cout << maxi <<'\n';
                return 0;
            }
        }
    }
    cout << maxi << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 452 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 7 ms 2264 KB Output is correct
3 Correct 47 ms 7244 KB Output is correct
4 Correct 23 ms 4056 KB Output is correct
5 Correct 23 ms 4056 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 46 ms 7460 KB Output is correct
9 Correct 29 ms 4300 KB Output is correct
10 Correct 59 ms 7360 KB Output is correct
11 Correct 22 ms 4052 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 47 ms 7400 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 29 ms 5668 KB Output is correct
6 Correct 36 ms 5576 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 900 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 37 ms 5740 KB Output is correct
18 Correct 36 ms 5840 KB Output is correct
19 Correct 1 ms 532 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 452 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 456 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 41 ms 5972 KB Output is correct
50 Correct 39 ms 5844 KB Output is correct
51 Correct 36 ms 5844 KB Output is correct
52 Correct 42 ms 5708 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 344 KB Output is correct
55 Correct 2 ms 604 KB Output is correct
56 Correct 2 ms 604 KB Output is correct
57 Incorrect 1 ms 348 KB Output isn't correct
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 24 ms 4064 KB Output is correct
3 Correct 22 ms 4056 KB Output is correct
4 Correct 29 ms 5844 KB Output is correct
5 Correct 36 ms 5844 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 38 ms 7248 KB Output is correct
9 Correct 40 ms 7336 KB Output is correct
10 Correct 51 ms 7360 KB Output is correct
11 Correct 52 ms 7368 KB Output is correct
12 Correct 61 ms 8136 KB Output is correct
13 Correct 74 ms 8648 KB Output is correct
14 Correct 50 ms 7452 KB Output is correct
15 Correct 41 ms 7364 KB Output is correct
16 Correct 47 ms 7360 KB Output is correct
17 Correct 51 ms 7564 KB Output is correct
18 Correct 79 ms 8900 KB Output is correct
19 Correct 58 ms 7360 KB Output is correct
20 Correct 51 ms 7372 KB Output is correct
21 Correct 50 ms 7108 KB Output is correct
22 Correct 65 ms 7364 KB Output is correct
23 Correct 75 ms 9920 KB Output is correct
24 Correct 55 ms 9920 KB Output is correct
25 Correct 53 ms 10032 KB Output is correct
26 Correct 68 ms 12024 KB Output is correct
27 Correct 65 ms 12224 KB Output is correct
28 Correct 68 ms 12736 KB Output is correct
29 Correct 44 ms 7368 KB Output is correct
30 Correct 52 ms 7452 KB Output is correct
31 Correct 44 ms 7364 KB Output is correct
32 Correct 58 ms 7368 KB Output is correct
33 Correct 46 ms 7372 KB Output is correct
34 Correct 21 ms 4060 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 460 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 70 ms 8944 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 34 ms 6120 KB Output is correct
53 Correct 31 ms 5940 KB Output is correct
54 Correct 29 ms 5844 KB Output is correct
55 Correct 35 ms 5816 KB Output is correct
56 Correct 35 ms 5844 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 7360 KB Output is correct
2 Correct 26 ms 4056 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 40 ms 7376 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 42 ms 7388 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 50 ms 8316 KB Output is correct
9 Correct 50 ms 7360 KB Output is correct
10 Correct 40 ms 7380 KB Output is correct
11 Correct 35 ms 7380 KB Output is correct
12 Correct 51 ms 7380 KB Output is correct
13 Correct 50 ms 7376 KB Output is correct
14 Correct 50 ms 7376 KB Output is correct
15 Correct 52 ms 7324 KB Output is correct
16 Correct 56 ms 10148 KB Output is correct
17 Correct 53 ms 10164 KB Output is correct
18 Correct 67 ms 9920 KB Output is correct
19 Correct 21 ms 3848 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 45 ms 7456 KB Output is correct
22 Correct 26 ms 4300 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 456 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 38 ms 3928 KB Output is correct
37 Correct 31 ms 5840 KB Output is correct
38 Correct 52 ms 5840 KB Output is correct
39 Correct 35 ms 5928 KB Output is correct
40 Correct 36 ms 5844 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 452 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 7 ms 2264 KB Output is correct
34 Correct 47 ms 7244 KB Output is correct
35 Correct 23 ms 4056 KB Output is correct
36 Correct 23 ms 4056 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 46 ms 7460 KB Output is correct
40 Correct 29 ms 4300 KB Output is correct
41 Correct 59 ms 7360 KB Output is correct
42 Correct 22 ms 4052 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 47 ms 7400 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 29 ms 5668 KB Output is correct
54 Correct 36 ms 5576 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 1 ms 764 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 2 ms 900 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 344 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 37 ms 5740 KB Output is correct
66 Correct 36 ms 5840 KB Output is correct
67 Correct 1 ms 532 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 1 ms 452 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 344 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 1 ms 344 KB Output is correct
79 Correct 1 ms 344 KB Output is correct
80 Correct 1 ms 348 KB Output is correct
81 Correct 0 ms 348 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 456 KB Output is correct
84 Correct 0 ms 344 KB Output is correct
85 Correct 0 ms 348 KB Output is correct
86 Correct 1 ms 348 KB Output is correct
87 Correct 0 ms 344 KB Output is correct
88 Correct 1 ms 348 KB Output is correct
89 Correct 1 ms 348 KB Output is correct
90 Correct 1 ms 344 KB Output is correct
91 Correct 0 ms 344 KB Output is correct
92 Correct 1 ms 348 KB Output is correct
93 Correct 0 ms 348 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 1 ms 348 KB Output is correct
97 Correct 41 ms 5972 KB Output is correct
98 Correct 39 ms 5844 KB Output is correct
99 Correct 36 ms 5844 KB Output is correct
100 Correct 42 ms 5708 KB Output is correct
101 Correct 1 ms 348 KB Output is correct
102 Correct 1 ms 344 KB Output is correct
103 Correct 2 ms 604 KB Output is correct
104 Correct 2 ms 604 KB Output is correct
105 Incorrect 1 ms 348 KB Output isn't correct
106 Halted 0 ms 0 KB -