답안 #555260

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
555260 2022-04-30T10:41:33 Z snasibov05 Usmjeravanje (COCI22_usmjeravanje) C++14
0 / 110
0 ms 212 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<int> res(m);
    int ca = a, cb = b;
    while (ca >= 1 || cb >= 1){
        if (ca >= 1 && froma[ca].empty()) {
            ans++; ca--;
            continue;
        }
        if (cb >= 1 && fromb[cb].empty()){
            ans++; cb--;
            continue;
        }

        int mxb = *froma[ca].begin();
        int mxa = *fromb[cb].begin();
        if (mxa == ca && mxb == cb) {
            ans += 2;
            ca--, cb--;
            continue;
        }

        while (ca >= mxa || cb >= mxb) {
            if (ca >= mxa) {
                if (!froma[ca].empty()) mxb = min(mxb, *froma[ca].begin());
                ca--;
                continue;
            }
            if (cb >= mxb) {
                if (!fromb[cb].empty()) {
                    mxa = min(mxa, *fromb[cb].begin());
                    if (mxa == *fromb[cb].begin()) res[id[make_pair(mxa, cb)]] = 1;
                }
                cb--;
            }
        }

        ans++;
    }

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

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -