Submission #1079303

# Submission time Handle Problem Language Result Execution time Memory
1079303 2024-08-28T12:49:47 Z raphaelp Tiles (BOI24_tiles) C++14
35 / 100
163 ms 19816 KB
#include <bits/stdc++.h>
using namespace std;
void add(vector<int> arete, int &impair, vector<int> &parity, set<vector<int>> &Intervals)
{
    if ((arete[2] - arete[1] + 1) % 2 == 1)
        impair++;
    parity[arete[0] % 2]++;
    Intervals.insert({arete[1], arete[2], arete[0] % 2});
}
int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> arete;
    vector<int> X(N), Y(N);
    for (int i = 0; i < N; i++)
    {
        cin >> X[i] >> Y[i];
    }
    for (int i = 0; i < N; i++)
    {
        if (X[(i + 1) % N] == X[i])
        {
            if (Y[i] < Y[(i + 1) % N])
                arete.push_back({X[i], min(Y[i], Y[(i + 1) % N]), max(Y[i], Y[(i + 1) % N]) - 1, 1});
            else
                arete.push_back({X[i], min(Y[i], Y[(i + 1) % N]), max(Y[i], Y[(i + 1) % N]) - 1, -1});
        }
    }
    sort(arete.begin(), arete.end());
    if (arete[0][3] == -1)
        for (int i = 0; i < arete.size(); i++)
            arete[i][3] = 0 - arete[i][3];
    int last = -1;
    int impair = 0;
    vector<int> parity(2);
    int maxx = 0;
    set<vector<int>> Intervals;
    for (int i = 0; i < arete.size(); i++)
    {
        if (arete[i][0] != last || i == arete[i].size() - 1)
        {
            last = arete[i][0];
            if (impair)
                break;
            if (parity[0] == 0 || parity[1] == 0)
            {
                int par = ((parity[1]) ? 1 : 0);
                maxx = ((arete[i][0] % 2 == par) ? arete[i][0] : (arete[i][0] - 1));
            }
        }
        if (arete[i][3] == 1)
        {
            auto pos = Intervals.lower_bound({arete[i][1]});
            if (pos != Intervals.end() && (*pos)[0] == arete[i][2] + 1 && (*pos)[2] == (arete[i][0] % 2))
            {
                arete[i][2] = (*pos)[1];
                if (((*pos)[1] - (*pos)[0] + 1) % 2 == 1)
                    impair--;
                parity[(*pos)[2]]--;
                pos = Intervals.erase(pos);
            }
            if (pos != Intervals.begin())
            {
                pos--;
                if ((*pos)[1] == arete[i][1] - 1 && (*pos)[2] == (arete[i][0] % 2))
                {
                    arete[i][1] = (*pos)[0];
                    if (((*pos)[1] - (*pos)[0] + 1) % 2 == 1)
                        impair--;
                    parity[(*pos)[2]]--;
                    Intervals.erase(pos);
                }
            }
            add(arete[i], impair, parity, Intervals);
        }
        else
        {
            auto pos = Intervals.upper_bound({arete[i][2]});
            pos--;
            if (arete[i][0] % 2 != (*pos)[2])
                break;
            if (arete[i][1] < (*pos)[0])
                break;
            int left = (*pos)[0], right = arete[i][1] - 1;
            if (right >= left)
            {
                add({(*pos)[2], left, right}, impair, parity, Intervals);
            }
            left = arete[i][2] + 1, right = (*pos)[1];
            if (right >= left)
            {
                add({(*pos)[2], left, right}, impair, parity, Intervals);
            }
            parity[(*pos)[2]]--;
            if ((((*pos)[1] - (*pos)[0]) % 2) == 0)
                impair--;
            Intervals.erase(pos);
        }
    }
    cout << maxx;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:32:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for (int i = 0; i < arete.size(); i++)
      |                         ~~^~~~~~~~~~~~~~
Main.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int i = 0; i < arete.size(); i++)
      |                     ~~^~~~~~~~~~~~~~
Main.cpp:41:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         if (arete[i][0] != last || i == arete[i].size() - 1)
      |                                    ~~^~~~~~~~~~~~~~~~~~~~~~
# 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 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 1 ms 436 KB Output is correct
8 Correct 0 ms 344 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 1 ms 436 KB Output is correct
8 Correct 0 ms 344 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 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 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 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 63 ms 3704 KB Output is correct
3 Correct 59 ms 3944 KB Output is correct
4 Correct 65 ms 7424 KB Output is correct
5 Correct 80 ms 8956 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 436 KB Output is correct
8 Correct 111 ms 11012 KB Output is correct
9 Correct 112 ms 11264 KB Output is correct
10 Correct 130 ms 11112 KB Output is correct
11 Correct 129 ms 11264 KB Output is correct
12 Correct 137 ms 12544 KB Output is correct
13 Correct 132 ms 13056 KB Output is correct
14 Correct 120 ms 11128 KB Output is correct
15 Correct 113 ms 11108 KB Output is correct
16 Correct 119 ms 11240 KB Output is correct
17 Correct 133 ms 11508 KB Output is correct
18 Correct 162 ms 13568 KB Output is correct
19 Correct 134 ms 11268 KB Output is correct
20 Correct 130 ms 11268 KB Output is correct
21 Correct 120 ms 11012 KB Output is correct
22 Correct 147 ms 11240 KB Output is correct
23 Correct 121 ms 15616 KB Output is correct
24 Correct 127 ms 15616 KB Output is correct
25 Correct 127 ms 15460 KB Output is correct
26 Correct 142 ms 19060 KB Output is correct
27 Correct 125 ms 19204 KB Output is correct
28 Correct 140 ms 19816 KB Output is correct
29 Correct 133 ms 11328 KB Output is correct
30 Correct 133 ms 11264 KB Output is correct
31 Correct 121 ms 11012 KB Output is correct
32 Correct 159 ms 11264 KB Output is correct
33 Correct 119 ms 11264 KB Output is correct
34 Correct 58 ms 5388 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 436 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 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 436 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 163 ms 13556 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 93 ms 9708 KB Output is correct
53 Correct 99 ms 8972 KB Output is correct
54 Correct 69 ms 8812 KB Output is correct
55 Correct 113 ms 8960 KB Output is correct
56 Correct 84 ms 8964 KB Output is correct
57 Correct 1 ms 348 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 Incorrect 118 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 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 1 ms 436 KB Output is correct
8 Correct 0 ms 344 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 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 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 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 1 ms 348 KB Output isn't correct
33 Halted 0 ms 0 KB -