Submission #198000

# Submission time Handle Problem Language Result Execution time Memory
198000 2020-01-24T13:01:02 Z model_code Slagalica (COCI19_slagalica2) C++17
70 / 70
49 ms 2684 KB
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; i++)

int n;

bool poc_izb = 0, kraj_izb = 0;
int cnt1 = 0, cnt4 = 0;

vector <pair <int, int> > lijevo_izb;
vector <pair <int, int> > lijevo_udub;
vector <pair <int, int> >::iterator izb, udub;

vector <int> rj;
int zadnji;

void nemoguce()
{
    printf("-1\n");
    exit(0);
    return;
}

int main()
{
    scanf("%d", &n);
    int x, a;
    FOR(i, 0, n)
    {
        scanf("%d%d", &x, &a);
        if(x == 5 || x == 6) rj.push_back(a);
        else if(x == 7 || x == 8) zadnji = a;
        if(x == 5) poc_izb = 1;
        else if(x == 7) kraj_izb = 1;
        else if(x == 1) cnt1++;
        else if(x == 4) cnt4++;
        if(x == 1 || x == 2) lijevo_izb.push_back(make_pair(a, x));
        else if(x == 3 || x == 4) lijevo_udub.push_back(make_pair(a, x));
    }
    if(poc_izb && kraj_izb && cnt4 != cnt1 + 1) nemoguce();
    if(!poc_izb && !kraj_izb && cnt1 != cnt4 + 1) nemoguce();
    if(poc_izb ^ kraj_izb)
    {
        if(cnt1 != cnt4) nemoguce();
        if(cnt1 == 0)
        {
            if(poc_izb && (int)lijevo_izb.size()) nemoguce();
            if(kraj_izb && (int)lijevo_udub.size()) nemoguce();
        }
    }
    sort(lijevo_izb.begin(), lijevo_izb.end());
    sort(lijevo_udub.begin(), lijevo_udub.end());
    int zadnja_promjena = 0;
    bool treba_izb = !poc_izb;
    izb = lijevo_izb.begin();
    udub = lijevo_udub.begin();
    while(!((izb == lijevo_izb.end() && treba_izb) || (udub == lijevo_udub.end() && !treba_izb)))
    {
        if(treba_izb)
        {
            if(izb -> second == 1)
            {
                treba_izb = 0;
                zadnja_promjena = (int)rj.size() - 1;
            }
            rj.push_back(izb -> first);
            izb++;
        }
        else
        {
            if(udub -> second == 4)
            {
                treba_izb = 1;
                zadnja_promjena = (int)rj.size() - 1;
            }
            rj.push_back(udub -> first);
            udub++;
        }
    }
    FOR(i, 0, zadnja_promjena + 1)
    {
        printf("%d ", rj[i]);
    }
    while(izb != lijevo_izb.end())
    {
        printf("%d ", izb -> first);
        izb++;
    }
    while(udub != lijevo_udub.end())
    {
        printf("%d ", udub -> first);
        udub++;
    }
    FOR(i, zadnja_promjena + 1, (int)rj.size())
    {
        printf("%d ", rj[i]);
    }
    printf("%d\n", zadnji);
    return 0;
}

Compilation message

slagalica.cpp: In function 'int main()':
slagalica.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
slagalica.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &a);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 2412 KB Output is correct
2 Correct 26 ms 1224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 2320 KB Output is correct
2 Correct 24 ms 1268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1392 KB Output is correct
2 Correct 43 ms 2308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1224 KB Output is correct
2 Correct 40 ms 2684 KB Output is correct
3 Correct 47 ms 2476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 2328 KB Output is correct
2 Correct 26 ms 1308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 2644 KB Output is correct
2 Correct 26 ms 1184 KB Output is correct
3 Correct 45 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1396 KB Output is correct
2 Correct 42 ms 2316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2624 KB Output is correct
2 Correct 24 ms 1268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 2344 KB Output is correct
2 Correct 25 ms 1392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 2628 KB Output is correct
2 Correct 27 ms 1268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 2272 KB Output is correct
2 Correct 25 ms 1308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 2192 KB Output is correct
2 Correct 27 ms 1300 KB Output is correct