Submission #634214

# Submission time Handle Problem Language Result Execution time Memory
634214 2022-08-24T06:43:33 Z HaYoungJoon Slagalica (COCI19_slagalica2) C++14
20 / 70
34 ms 2980 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;
    }
    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;
    for (int i = res.size() - 1; i >= 0; i--) {
        if (change[res[i].first].second != change[id].first) {
            pos = i;
            break;
        }
    }
    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 < res.size(); i++) cout << res[i].second << ' ';
    return 0;
}

Compilation message

slagalica.cpp: In function 'int main()':
slagalica.cpp:95:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for (int i = pos+1; i < res.size(); i++) cout << res[i].second << ' ';
      |                         ~~^~~~~~~~~~~~
slagalica.cpp:95:14: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   95 |     for (int i = pos+1; i < res.size(); i++) cout << res[i].second << ' ';
      |              ^
# 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 19 ms 1576 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 1424 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1244 KB Output is correct
2 Runtime error 20 ms 2004 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1276 KB Output is correct
2 Correct 30 ms 2116 KB Output is correct
3 Runtime error 23 ms 1812 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1908 KB Output is correct
2 Runtime error 20 ms 1508 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 21 ms 1308 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1988 KB Output is correct
2 Incorrect 21 ms 1792 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2700 KB Output is correct
2 Correct 20 ms 2756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 2236 KB Output is correct
2 Correct 19 ms 2844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 1856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 1868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 2328 KB Output is correct
2 Correct 26 ms 2980 KB Output is correct