Submission #540148

# Submission time Handle Problem Language Result Execution time Memory
540148 2022-03-19T11:52:33 Z model_code Usmjeravanje (COCI22_usmjeravanje) C++17
110 / 110
212 ms 16960 KB
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
#define X first
#define Y second

using namespace std;

const int MAXN = 500100;
vector <pair <int, int> > ve[2];
map <pair <int, int>, int> ind;
int sol[MAXN];

int main() {
    ios_base::sync_with_stdio(false);

    int A, B, m;
    cin >> A >> B >> m;

    REP(i, m) {
        int x, y;
        cin >> x >> y;

        ve[0].push_back({x, y});
        ve[1].push_back({y, x});
        ind[{x, y}] = i;
    }

    sort(ve[0].begin(), ve[0].end());
    sort(ve[1].begin(), ve[1].end());

    int x = 0, y = 0;
    int out = A + B;

    while (x < ve[0].size() && y < ve[1].size()) {
        int X = ve[0][x].first, Y = ve[1][y].first;

        int u = ve[1][y].second;
        int d = ve[0][x].second;

        sol[ind[ve[0][x]]] = 1;

        bool flag = true;
        while (flag) {
            flag = false;
            if (x < ve[0].size() && ve[0][x].first <= u) {
                if (d < ve[0][x].second)  sol[ind[ve[0][x]]] = 1;
                d = max(d, ve[0][x].second);
                x++;
                flag = true;
            }
            if (y < ve[1].size() && ve[1][y].first <= d) {
                u = max(u, ve[1][y].second);
                y++;
                flag = true;
            }
        }

        if (u == X && d == Y) continue;
        if (u == X) sol[ind[{X, Y}]] = 0;
        if (d == Y) sol[ind[{X, Y}]] = 1;

        out -= (u - X + 1) + (d - Y + 1) - 1;

        /*cout << X << " " << u << endl;
        cout << Y << " " << d << endl;
        cout << "------\n";*/
    }

    cout << out << "\n";
    REP(i, m) cout << sol[i] << " ";

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:37:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     while (x < ve[0].size() && y < ve[1].size()) {
      |            ~~^~~~~~~~~~~~~~
Main.cpp:37:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     while (x < ve[0].size() && y < ve[1].size()) {
      |                                ~~^~~~~~~~~~~~~~
Main.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |             if (x < ve[0].size() && ve[0][x].first <= u) {
      |                 ~~^~~~~~~~~~~~~~
Main.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |             if (y < ve[1].size() && ve[1][y].first <= d) {
      |                 ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 4 ms 732 KB Output is correct
19 Correct 4 ms 724 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 8 ms 1236 KB Output is correct
22 Correct 51 ms 6052 KB Output is correct
23 Correct 72 ms 7828 KB Output is correct
24 Correct 141 ms 12232 KB Output is correct
25 Correct 67 ms 7236 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 4 ms 732 KB Output is correct
19 Correct 4 ms 724 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 8 ms 1236 KB Output is correct
22 Correct 51 ms 6052 KB Output is correct
23 Correct 72 ms 7828 KB Output is correct
24 Correct 141 ms 12232 KB Output is correct
25 Correct 67 ms 7236 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 392 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 5 ms 852 KB Output is correct
42 Correct 5 ms 824 KB Output is correct
43 Correct 8 ms 1240 KB Output is correct
44 Correct 2 ms 472 KB Output is correct
45 Correct 145 ms 10760 KB Output is correct
46 Correct 23 ms 3140 KB Output is correct
47 Correct 141 ms 13128 KB Output is correct
48 Correct 42 ms 5040 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 166 ms 14692 KB Output is correct
52 Correct 142 ms 12932 KB Output is correct
53 Correct 212 ms 16340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 96 ms 8728 KB Output is correct
57 Correct 189 ms 16960 KB Output is correct
58 Correct 13 ms 1920 KB Output is correct
59 Correct 15 ms 1944 KB Output is correct
60 Correct 16 ms 1920 KB Output is correct
61 Correct 17 ms 1964 KB Output is correct
62 Correct 151 ms 16652 KB Output is correct