Submission #209332

# Submission time Handle Problem Language Result Execution time Memory
209332 2020-03-13T20:09:53 Z papa Drvca (COCI19_drvca) C++14
0 / 110
108 ms 12664 KB
#include <bits/stdc++.h>

using namespace std;

//zapazamo da jedan od nizova mora poceti
//kombinacijom a[1]-a[2] ili a[1]-a[3] ili a[2]-a[3]
//i proveravamo da li moze da se formira niz
//ako su prva broja bas ta dva
//formiramo dok moze i kad vise ne moze vidimo da li i preostali brojevi
//formiraju aritmeticki niz
//ako formiraju nasli smo resenje
//provera pomocu seta radimo

int n;
int h[100005];
multiset<int> se;
vector<int> red1;
vector<int> red2;
multiset<int> temp;
int dif;

void f1()
{
    cout << 1 << "\n";
    cout << red1[0] << "\n";
    cout << n-1 << "\n";
    for(int i=1;i<n;i++) cout << red1[i] << " ";
}

void stampa()
{
    cout << red1.size() << "\n";
    for(int x : red1) cout << x << " ";
    cout << "\n";
    cout << red2.size() << "\n";
    for(int x : red2) cout << x << " ";
}

bool check()
{
    int dif = -1;
    for(int i=1;i<red2.size();i++)
    {
        if(dif==-1)
        {
            dif=red2[i]-red2[i-1];
            continue;
        }
        if(red2[i]-red2[i-1]!=dif) return false;
    }

    return true;
}

void probaj(int a,int b)
{
    temp = se;
    red1.push_back(a);
    red1.push_back(b);
    temp.erase(a);
    temp.erase(b);
    dif = b-a;
    int nxt = b+dif;
    multiset<int>::iterator itr;
    while(!temp.empty() && temp.find(nxt)!=temp.end())
    {
        itr = temp.find(nxt);
        red1.push_back(nxt);
        temp.erase(itr);
        nxt=nxt+dif;
    }

    if(red1.size()==n)
    {
        f1();
        exit(0);
    }
    else
    {
        for(int xx : temp) red2.push_back(xx);
        if(check())
        {
            stampa();
            exit(0);
        }
    }
}

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

    cin >> n;

    for(int i=1;i<=n;i++)
    {
        cin >> h[i];
        se.insert(h[i]);
    }

    if(n==2)
    {
        cout << 1 << "\n";
        cout << h[1] << "\n";
        cout << 1 << "\n";
        cout << h[2] << "\n";

        return 0;
    }

    sort(h+1,h+n+1);

    probaj(h[1],h[2]);
    //cout << "proso";
    probaj(h[2],h[3]);
    //cout << "proso";
    probaj(h[1],h[3]);

    cout << -1;

    return 0;
}

Compilation message

drvca.cpp: In function 'bool check()':
drvca.cpp:42:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<red2.size();i++)
                 ~^~~~~~~~~~~~
drvca.cpp: In function 'void probaj(int, int)':
drvca.cpp:73:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(red1.size()==n)
        ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Incorrect 5 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Incorrect 5 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 12660 KB Output is correct
2 Correct 93 ms 11128 KB Output is correct
3 Correct 100 ms 12664 KB Output is correct
4 Correct 88 ms 11128 KB Output is correct
5 Correct 102 ms 12660 KB Output is correct
6 Correct 93 ms 11128 KB Output is correct
7 Correct 100 ms 12660 KB Output is correct
8 Correct 88 ms 11128 KB Output is correct
9 Incorrect 108 ms 12400 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Incorrect 5 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -