Submission #209330

# Submission time Handle Problem Language Result Execution time Memory
209330 2020-03-13T20:09:06 Z papa Slagalica (COCI19_slagalica2) C++14
45 / 70
48 ms 3820 KB
#include <bits/stdc++.h>

using namespace std;

//treba da se doradi !!!

int n;
bool pi = 0;
bool ki = 0;
int cnt1 =0;
int cnt4 =0;

vector<pair<int,int> > li;
vector<pair<int,int> > lu;
vector<pair<int,int> >::iterator iz,ud;

vector<int> rj;
int zadnji;

void nemoguce()
{
    cout << -1;
    exit(0);
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);

    cin >> n;

    for(int i=0;i<n;i++)
    {
        int x,a;
        cin >> x >> a;

        if(x==5 || x==6) rj.push_back(a);
        else if(x==7 || x==8) zadnji = a;
        if(x==5) pi = 1;
        else if(x==7) ki = 1;
        else if(x==1) cnt1++;
        else if(x==4) cnt4++;
        if(x==1 || x==2) li.push_back({a,x});
        else if(x==3 || x==4) lu.push_back({a,x});
    }

    if(pi && ki && cnt4!=cnt1+1) nemoguce();
    if(!pi && !ki && cnt4!=cnt1+1) nemoguce();
    if(pi ^ ki)
    {
        if(cnt1!=cnt4) nemoguce();
        if(cnt1==0)
        {
            if(pi && li.size()) nemoguce();
            if(ki && lu.size()) nemoguce();
        }
    }

    sort(li.begin(),li.end());
    sort(lu.begin(),lu.end());
    int prom = 0;
    bool treba = !pi;
    iz = li.begin();
    ud = lu.begin();

    while(!((iz==li.end() && treba) || (ud==lu.end() && !treba)))
    {
        if(treba)
        {
            if(iz->second==1)
            {
                treba = 0;
                prom = rj.size()-1;
            }
            rj.push_back(iz->first);
            iz++;
        }
        else
        {
            if(ud->second==4)
            {
                treba = 1;
                prom = rj.size()-1;
            }
            rj.push_back(ud->first);
            ud++;
        }
    }

    for(int i=0;i<prom+1;i++) cout << rj[i] << " ";
    while(iz!=li.end())
    {
        cout << iz->first << " ";
        iz++;
    }

    while(ud!=lu.end())
    {
        cout << ud->first << " ";
        ud++;
    }

    for(int i=prom+1;i<rj.size();i++) cout << rj[i] << " ";

    cout << zadnji;

    return 0;
}

Compilation message

slagalica.cpp: In function 'int main()':
slagalica.cpp:107:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=prom+1;i<rj.size();i++) cout << rj[i] << " ";
                      ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Incorrect 5 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 3412 KB Output is correct
2 Correct 25 ms 2320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 3244 KB Output is correct
2 Correct 26 ms 2420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2540 KB Output is correct
2 Incorrect 25 ms 2420 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 2288 KB Output is correct
2 Correct 38 ms 3548 KB Output is correct
3 Incorrect 27 ms 2368 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 3372 KB Output is correct
2 Correct 25 ms 2292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 3760 KB Output is correct
2 Correct 29 ms 2292 KB Output is correct
3 Correct 41 ms 3560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2416 KB Output is correct
2 Incorrect 24 ms 2208 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 3820 KB Output is correct
2 Correct 24 ms 2412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 3192 KB Output is correct
2 Correct 23 ms 2288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 2412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 3460 KB Output is correct
2 Correct 24 ms 2272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 3304 KB Output is correct
2 Correct 26 ms 2288 KB Output is correct