답안 #634223

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634223 2022-08-24T06:55:50 Z HaYoungJoon Slagalica (COCI19_slagalica2) C++14
20 / 70
29 ms 2600 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;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 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
# 결과 실행 시간 메모리 Grader output
1 Runtime error 17 ms 1556 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 1312 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1304 KB Output is correct
2 Runtime error 19 ms 1996 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 1248 KB Output is correct
2 Correct 24 ms 2224 KB Output is correct
3 Runtime error 23 ms 1908 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 2012 KB Output is correct
2 Runtime error 19 ms 1488 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 1352 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 1976 KB Output is correct
2 Incorrect 18 ms 1812 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 2600 KB Output is correct
2 Correct 18 ms 1740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 2208 KB Output is correct
2 Correct 22 ms 1816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 1868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 1860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2340 KB Output is correct
2 Correct 20 ms 1896 KB Output is correct