Submission #555227

# Submission time Handle Problem Language Result Execution time Memory
555227 2022-04-30T09:48:23 Z snasibov05 Usmjeravanje (COCI22_usmjeravanje) C++14
0 / 110
1 ms 300 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
    int a, b; cin >> a >> b;
    int m; cin >> m;
    vector<set<int>> froma(a+1), fromb(b+1);
    map<pair<int, int>, int> id;
    for (int i = 0; i < m; ++i){
        int x, y; cin >> x >> y;
        id[make_pair(x, y)] = i;
        froma[x].insert(y);
        fromb[y].insert(x);
    }

    int ans = 0;
    vector<pair<int, int>> cmpa, cmpb;
    vector<int> res(m);
    int ca = a, cb = b;
    while (ca >= 1 && cb >= 1){
        if (froma[ca].empty()) {
            if (cmpa.empty() || ca < cmpa.back().first) ans++;
            ca--;
            continue;
        }
        if (fromb[cb].empty()){
            if (cmpb.empty() || cb < cmpb.back().first) ans++;
            cb--;
            continue;
        }

        int mxb = *froma[ca].begin();
        int mxa = *fromb[cb].begin();
        if (mxa == ca && mxb == cb) {
            if (cmpa.empty() || ca < cmpa.back().first) ans++;
            if (cmpb.empty() || cb < cmpb.back().first) ans++;
            ca--, cb--;
            continue;
        }

        if (mxa == ca){
            res[id[{ca, cb}]] = 1;
            froma[ca].erase(cb);
        }

        cmpa.push_back({mxa, ca});
        cmpb.push_back({mxb, cb});

        for (auto x : froma[ca]) {
            res[id[{ca, x}]] = 0;
            fromb[x].erase(ca);
        }
        for (auto x : fromb[cb]){
            res[id[{x, cb}]] = 1;
            froma[x].erase(cb);
        }
        ca--, cb--;
    }

    while (ca >= 1){
        if (cmpa.empty() || ca < cmpa.back().first) ans++;
        ca--;
    }

    while (cb >= 1){
        if (cmpb.empty() || cb < cmpb.back().first) ans++;
        cb--;
    }

    ans += cmpa.size();
    reverse(cmpa.begin(), cmpa.end());
    reverse(cmpb.begin(), cmpb.end());
    for (int i = 0; i < cmpa.size() - 1; ++i){
        if (cmpa[i].second >= cmpa[i+1].first || cmpb[i].second >= cmpb[i+1].first) ans--;
    }

    cout << ans << "\n";
    for (auto x : res) cout << x << " ";
    cout << "\n";

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:74:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for (int i = 0; i < cmpa.size() - 1; ++i){
      |                     ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -