Submission #634224

# Submission time Handle Problem Language Result Execution time Memory
634224 2022-08-24T06:56:11 Z HaYoungJoon Slagalica (COCI19_slagalica2) C++14
20 / 70
33 ms 2744 KB
#include <bits/stdc++.h>
#define fi first
#define se second

using namespace std;

typedef pair<int,int> pii;
pii change[9];
int n;
vector<int> type[9];

void makeChange() {
    change[1] = pii(1,1);
    change[2] = pii(1,2);
    change[3] = pii(2,1);
    change[4] = pii(2,2);
    change[5] = pii(0,1);
    change[6] = pii(0,2);
    change[7] = pii(1,0);
    change[8] = pii(2,0);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    makeChange();
    for (int i = 1; i <= n; i++) {
        int t,id;
        cin >> t >> id;
        type[t].push_back(id);
    }
    for (int i = 1; i <= 4; i++) sort(type[i].begin(),type[i].end(),greater<int> {});
    int st = (type[5].empty()) ? 6: 5;
    int fin = (type[7].empty()) ? 8: 7;
    vector<pii> res;
    res.push_back(pii(st,type[st].back()));
    bool found = 1;
    int pre = change[st].second;
    while (found) {
        int id;
        if (pre == 1) {
            if (type[3].empty() && type[4].empty()) found = 0;
            else if (type[3].empty() || type[4].back() < type[3].back()) {
                res.push_back(pii(4,type[4].back()));
                type[4].pop_back();
                id = 4;
            } else {
                res.push_back(pii(3,type[3].back()));
                type[3].pop_back();
                id = 3;
            }
        } else {
            if (type[1].empty() && type[2].empty()) found = 0;
            else if (type[1].empty() || type[2].back() < type[1].back()) {
                res.push_back(pii(2,type[2].back()));
                type[2].pop_back();
                id = 2;
            } else {
                res.push_back(pii(1,type[1].back()));
                type[1].pop_back();
                id = 1;
            }
        }
        if (found) pre = change[id].second;
    }
 //   assert(!res.empty());
    if (change[res.back().first].second == change[fin].first) {
        cout << -1;
        return 0;
    }
    if (!type[1].empty()) {
        cout << -1;
        return 0;
    }
    if (!type[4].empty()) {
        cout << -1;
        return 0;
    }
    int id;
    if (type[2].empty() && type[3].empty()) {
        res.push_back(pii(fin,type[fin].back()));
        for (pii i: res) cout << i.second << ' ';
        return 0;
    } else id = (type[2].empty()) ? 3: 2;
    int pos = -1;
    for (int i = res.size() - 1; i >= 0; i--) {
        if (change[res[i].first].second != change[id].first) {
            pos = i;
            break;
        }
    }
    assert(pos != -1);
    for (int i = 0; i <= pos; i++) cout << res[i].second << ' ';
    for (int i = type[id].size() - 1; i >= 0; i--) cout << type[id][i] << ' ';
    res.push_back(pii(fin,type[fin].back()));
    for (int i = pos+1; i < (int) res.size(); i++) cout << res[i].second << ' ';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 20 ms 1548 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 20 ms 1424 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1372 KB Output is correct
2 Runtime error 21 ms 2020 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1200 KB Output is correct
2 Correct 29 ms 2124 KB Output is correct
3 Runtime error 21 ms 1876 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1988 KB Output is correct
2 Runtime error 20 ms 1476 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 1304 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1940 KB Output is correct
2 Incorrect 19 ms 1748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2744 KB Output is correct
2 Correct 18 ms 1760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 2212 KB Output is correct
2 Correct 19 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 1880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 2332 KB Output is correct
2 Correct 20 ms 1892 KB Output is correct