Submission #711630

# Submission time Handle Problem Language Result Execution time Memory
711630 2023-03-17T10:04:01 Z becaido Slagalica (COCI19_slagalica2) C++17
70 / 70
51 ms 3008 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof... (u) ? ", " : ""), dout (u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 1e5 + 5;
const int lt[8] = {-1, -1, 1, 1, 0, 0, -1, 1};
const int rt[8] = {1, -1, 1, -1, 1, -1, 0, 0};

int n;
int sty, ety, sx, ex;
priority_queue<int, vector<int>, greater<int>> pq[4];

void no() {
    cout << "-1\n";
    exit(0);
}

void out(int i) {
    cout << pq[i].top() << ' ';
    pq[i].pop();
}

void solve() {
    cin >> n;
    FOR (i, 1, n) {
        int ty, x;
        cin >> ty >> x;
        ty--;
        if (ty == 4 || ty == 5) {
            sty = ty == 4 ? 1 : -1;
            sx = x;
        } else if (ty == 6 || ty == 7) {
            ety = ty == 6 ? -1 : 1;
            ex = x;
        } else {
            pq[ty].push(x);
        }
    }

    if (sty == -1) {
        if (ety == -1) {
            if (pq[0].size() != pq[3].size() || (!pq[0].size() && pq[2].size())) no();
        }
        if (ety == 1) {
            if (pq[0].size() != pq[3].size() + 1) no();
        }
    }
    if (sty == 1) {
        if (ety == -1) {
            if (pq[0].size() + 1 != pq[3].size()) no();
        }
        if (ety == 1) {
            if (pq[0].size() != pq[3].size() || (!pq[0].size() && pq[1].size())) no();
        }
    }

    cout << sx << ' ';
    int cur = sty;

    while (pq[0].size() + pq[1].size() + pq[2].size() + pq[3].size()) {
        int mn[4];
        FOR (i, 0, 3) mn[i] = pq[i].size() ? pq[i].top() : INT_MAX;

        if (cur == -1) {
            if (mn[1] < mn[0] || (ety == 1 && pq[3].size() == 0 && pq[1].size())) out(1);
            else out(0), cur = -cur;
        } else {
            if (mn[2] < mn[3] || (ety == -1 && pq[0].size() == 0 && pq[2].size())) out(2);
            else out(3), cur = -cur;
        }
    }
    cout << ex << '\n';
}

int main() {
    Waimai;
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 2620 KB Output is correct
2 Correct 17 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2500 KB Output is correct
2 Correct 17 ms 1808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2028 KB Output is correct
2 Correct 35 ms 2716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1788 KB Output is correct
2 Correct 39 ms 2508 KB Output is correct
3 Correct 37 ms 2836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2620 KB Output is correct
2 Correct 18 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2508 KB Output is correct
2 Correct 17 ms 1856 KB Output is correct
3 Correct 37 ms 2824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1832 KB Output is correct
2 Correct 31 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 3008 KB Output is correct
2 Correct 19 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 2464 KB Output is correct
2 Correct 17 ms 1864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 2928 KB Output is correct
2 Correct 19 ms 1976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 2588 KB Output is correct
2 Correct 16 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2672 KB Output is correct
2 Correct 20 ms 1928 KB Output is correct