Submission #1079398

# Submission time Handle Problem Language Result Execution time Memory
1079398 2024-08-28T13:55:00 Z raphaelp Tiles (BOI24_tiles) C++14
24 / 100
156 ms 9924 KB
#include <bits/stdc++.h>
using namespace std;

struct segment
{
    int l, r, par, type;
};
bool operator<(segment a, segment b)
{
    if (a.l == b.l)
        return a.r < b.r;
    return a.l < b.l;
}
void remove(auto pos, set<segment> &Intervals, int &impair, vector<int> &parity)
{
    if (((*pos).r - (*pos).l + 1) % 2)
        impair--;
    parity[(*pos).par]--;
    pos = Intervals.erase(pos);
}
void add(segment arete, int &impair, vector<int> &parity, set<segment> &Intervals)
{
    if ((arete.r - arete.l + 1) % 2 == 1)
        impair++;
    parity[arete.par % 2]++;
    Intervals.insert({arete.l, arete.r, arete.par % 2});
}
int N;
int next(int i) { return (i + 1) % N; }
int main()
{
    auto comp = [&](segment a, segment b)
    {
        return a.par < b.par;
    };
    int M;
    cin >> N >> M;
    vector<segment> 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[next(i)] == X[i])
        {
            if (Y[i] < Y[next(i)])
                arete.push_back({min(Y[i], Y[next(i)]), max(Y[i], Y[next(i)]) - 1, X[i], 1});
            else
                arete.push_back({min(Y[i], Y[next(i)]), max(Y[i], Y[next(i)]) - 1, X[i], -1});
        }
    }
    sort(arete.begin(), arete.end(), comp);
    if (arete[0].type == -1)
        for (int i = 0; i < arete.size(); i++)
            arete[i].type = 0 - arete[i].type;
    int last = -1;
    int impair = 0;
    vector<int> parity(2);
    int maxx = 0;
    set<segment> Intervals;
    for (int i = 0; i < arete.size(); i++)
    {
        if (arete[i].par != last || i == arete.size() - 1)
        {
            last = arete[i].par;
            if (impair)
                break;
            if (parity[0] == 0 || parity[1] == 0)
            {
                int par = ((parity[1]) ? 1 : 0);
                maxx = ((arete[i].par % 2 == par) ? arete[i].par : (arete[i].par - 1));
            }
        }
        if (arete[i].type == 1)
        {
            auto pos = Intervals.lower_bound({arete[i].l});
            if (pos != Intervals.end() && (*pos).l == arete[i].r + 1 && (*pos).par == (arete[i].par % 2))
            {
                arete[i].r = (*pos).r;
                remove(pos, Intervals, impair, parity);
            }
            if (pos != Intervals.begin())
            {
                pos--;
                if ((*pos).r == arete[i].l - 1 && (*pos).par == (arete[i].par % 2))
                {
                    arete[i].l = (*pos).l;
                    remove(pos, Intervals, impair, parity);
                }
            }
            add(arete[i], impair, parity, Intervals);
        }
        else
        {
            auto pos = Intervals.lower_bound({arete[i].r + 1});
            pos--;
            if ((arete[i].par % 2) != (*pos).par)
                break;
            if (arete[i].l < (*pos).l)
                break;
            int left = (*pos).l, right = arete[i].l - 1;
            if (right >= left)
            {
                add({left, right, (*pos).par}, impair, parity, Intervals);
            }
            left = arete[i].r + 1, right = (*pos).r;
            if (right >= left)
            {
                add({left, right, (*pos).par}, impair, parity, Intervals);
            }
            remove(pos, Intervals, impair, parity);
        }
    }
    cout << maxx;
}

Compilation message

Main.cpp:14:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   14 | void remove(auto pos, set<segment> &Intervals, int &impair, vector<int> &parity)
      |             ^~~~
Main.cpp: In function 'int main()':
Main.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<segment>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for (int i = 0; i < arete.size(); i++)
      |                         ~~^~~~~~~~~~~~~~
Main.cpp:63:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<segment>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for (int i = 0; i < arete.size(); i++)
      |                     ~~^~~~~~~~~~~~~~
Main.cpp:65:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<segment>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         if (arete[i].par != last || i == arete.size() - 1)
      |                                     ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 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 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 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 1 ms 344 KB Output is correct
2 Correct 1 ms 344 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 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 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 0 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 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 436 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 344 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 Correct 1 ms 348 KB Output is correct
2 Correct 19 ms 1740 KB Output is correct
3 Correct 106 ms 7816 KB Output is correct
4 Correct 54 ms 4296 KB Output is correct
5 Correct 53 ms 4296 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 110 ms 7856 KB Output is correct
9 Correct 63 ms 4556 KB Output is correct
10 Correct 107 ms 7844 KB Output is correct
11 Correct 65 ms 3788 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 111 ms 7868 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 432 KB Output is correct
3 Runtime error 1 ms 348 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 54 ms 2360 KB Output is correct
3 Correct 54 ms 2252 KB Output is correct
4 Correct 56 ms 4172 KB Output is correct
5 Correct 65 ms 4172 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 102 ms 4156 KB Output is correct
9 Correct 99 ms 4036 KB Output is correct
10 Correct 104 ms 4036 KB Output is correct
11 Correct 109 ms 4040 KB Output is correct
12 Correct 118 ms 4660 KB Output is correct
13 Correct 122 ms 4804 KB Output is correct
14 Correct 104 ms 4172 KB Output is correct
15 Correct 100 ms 4040 KB Output is correct
16 Incorrect 102 ms 4168 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 116 ms 4124 KB Output is correct
2 Correct 59 ms 4300 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 104 ms 7852 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 109 ms 7876 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 116 ms 8388 KB Output is correct
9 Correct 156 ms 7980 KB Output is correct
10 Correct 134 ms 7976 KB Output is correct
11 Correct 104 ms 7860 KB Output is correct
12 Correct 106 ms 7880 KB Output is correct
13 Correct 107 ms 7724 KB Output is correct
14 Correct 112 ms 7876 KB Output is correct
15 Correct 115 ms 7980 KB Output is correct
16 Correct 149 ms 9924 KB Output is correct
17 Correct 122 ms 9924 KB Output is correct
18 Correct 118 ms 9896 KB Output is correct
19 Correct 52 ms 4148 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 104 ms 7848 KB Output is correct
22 Correct 66 ms 4552 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 344 KB Output is correct
27 Correct 1 ms 440 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 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 66 ms 4296 KB Output is correct
37 Correct 62 ms 5572 KB Output is correct
38 Correct 61 ms 5576 KB Output is correct
39 Correct 62 ms 5576 KB Output is correct
40 Correct 62 ms 5564 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 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Runtime error 1 ms 604 KB Execution killed with signal 11
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 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 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 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 0 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 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 436 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 344 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 Correct 1 ms 348 KB Output is correct
33 Correct 19 ms 1740 KB Output is correct
34 Correct 106 ms 7816 KB Output is correct
35 Correct 54 ms 4296 KB Output is correct
36 Correct 53 ms 4296 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 110 ms 7856 KB Output is correct
40 Correct 63 ms 4556 KB Output is correct
41 Correct 107 ms 7844 KB Output is correct
42 Correct 65 ms 3788 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 111 ms 7868 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 432 KB Output is correct
51 Runtime error 1 ms 348 KB Execution killed with signal 11
52 Halted 0 ms 0 KB -