Submission #1013122

# Submission time Handle Problem Language Result Execution time Memory
1013122 2024-07-03T08:11:22 Z vjudge1 Slagalica (COCI19_slagalica2) C++17
5 / 70
62 ms 2764 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;

    vector<int> vec[10], g[10];
    int lin = 0, lout = 0, rin = 0, rout = 0;
    for (int i = 0; i < n; i ++){
        int x, y;
        cin >> x >> y;
        vec[x].push_back(y);

        lin += (x == 3 or x == 4 or x == 8);
        lout += (x == 1 or x == 2 or x == 7);
        rin += (x == 2 or x == 4 or x == 6);
        rout += (x == 1 or x == 3 or x == 5);
    }
    for (int i = 1; i <= 8; i ++)
        sort(vec[i].rbegin(), vec[i].rend());

    


    g[5] = {3, 4};
    g[6] = {1, 2};
    g[1] = {3, 4, 8};
    g[2] = {1, 2, 7};
    g[3] = {3, 4, 8};
    g[4] = {1, 2, 7};

    vector<int> answer, types;
    int lm = 1, rm;
    for (int x : vec[5]){
        answer.push_back(x);
        types.push_back(5);
        rout--;
        lm = 1;
    }
    for (int x : vec[6]){
        answer.push_back(x);
        types.push_back(6);
        rin--;
        lm = 0;
    }

    if (vec[7].size())
        rm = 1;
    else
        rm = 0;

    while (1){
        int last = types.back();
        int min_t = -1;
        for (int t : g[last]){
            if (vec[t].size() == 0) continue;
            if (t == 3 and vec[1].size() == 0){
                min_t = 3;
                break;
            }
            if (t == 1 and vec[1].size() == 1 and vec[2].size() > 0) continue;
            if (vec[t].size() and (min_t == -1 or vec[min_t].back() > vec[t].back()))
                min_t = t;
        }

        bool all = 1;
        for (int i = 1; i <= 4; i ++)
            all &= (vec[i].size() == 0);
        if (all) break;

        if (!all and min_t == -1){
            cout << -1 << endl;
            return 0;
        } 

        types.push_back(min_t);
        answer.push_back(vec[min_t].back());
        vec[min_t].pop_back();
    }

    int last = types.back();
    int have = 7;
    if (vec[8].size()) have = 8;

    if ((have == 7 and (last == 2 or last == 4)) or (have == 8 and (last == 1 or last == 3)))
        answer.push_back(vec[have][0]);
    else{
        cout << -1 << endl;
        return 0;
    }

    for (int x : answer)
        cout << x << " ";
    cout << endl;
}

Compilation message

slagalica.cpp: In function 'int main()':
slagalica.cpp:34:9: warning: variable 'lm' set but not used [-Wunused-but-set-variable]
   34 |     int lm = 1, rm;
      |         ^~
slagalica.cpp:34:17: warning: variable 'rm' set but not used [-Wunused-but-set-variable]
   34 |     int lm = 1, rm;
      |                 ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 1296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 1168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 1272 KB Output is correct
2 Correct 38 ms 2288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 888 KB Output is correct
2 Incorrect 33 ms 1432 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 1276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2764 KB Output is correct
2 Correct 38 ms 876 KB Output is correct
3 Incorrect 35 ms 1716 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 860 KB Output is correct
2 Incorrect 31 ms 1164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 1408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 1432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 1884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 1028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 1636 KB Output isn't correct
2 Halted 0 ms 0 KB -