Submission #831753

#TimeUsernameProblemLanguageResultExecution timeMemory
831753Chal1shkanDrvca (COCI19_drvca)C++14
110 / 110
139 ms13376 KiB
# include <bits/stdc++.h>

# define mkp make_pair
# define ff first
# define ss second
# define pll pair <ll, ll>
# define pii pair <int, int>
  
# define vec vector
# define pb push_back
# define pf push_front
# define ppb pop_back
# define ppf pop_front
  
# define all(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
# define sz(x) ((int)(x).size())
# define lb lower_bound
# define ub upper_bound
  
# define br break
# define rt return 
# define cn continue
# define nl "\n"
# define off exit(0)
  
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
  
const ll MAXN = 1e5 + 25;
const ll MAXL = 18 + 0;
const ll INF = 1e18 + 0;
const ll inf = 2e9 + 0;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ld PI = acos( (ld) -1 );
const ll P = 67 + 0 + 0;
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  
using namespace std;
 
void open (string fname = "")
{
    if (fname.size())
    {
        freopen((fname + ".in").c_str(), "r", stdin);
        freopen((fname + ".out").c_str(), "w", stdout);
    }
}
 
void qataima ()
{
    ios::sync_with_stdio(false);
  
    cin.tie(0);    
    
	//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
}

ll n, a[MAXN];

void solve (ll ps1, ll ps2)
{
	ll d = a[ps2] - a[ps1];
	multiset <ll> s;
	multiset <ll> st;
	for (ll i = 1; i <= n; ++i)
	{
		if (i != ps1 && i != ps2)
		{
			s.insert(a[i]);
		}
	}
	if (sz(s) > 1)
	{
		auto lastt = s.end();
		--lastt;
    	auto itt = s.begin();
    	while (itt != lastt)
    	{
    		itt++;
    		ll x = *itt;
    		itt--;
    		ll y = *itt;
    		st.insert(x - y);
    		itt++;
    	}
	}
	vec <ll> x = {a[ps1], a[ps2]}, y;
	ll cnt = 2;
	while (!s.empty())
	{
		if (*st.begin() == *st.rbegin())
		{
			br;
		}
		else
		{
			ll next = a[ps1] + d * cnt;
			if (s.count(next))
			{
				auto it = s.find(next);
				ll num1 = -1, num2 = -1;
				if (it != s.begin())
				{
					it--;
					num1 = *it;
					st.erase(st.find(next - num1));
					it++;
				}
				auto lastt = s.end();
				--lastt;
				if (it != lastt)
				{
					it++;
					num2 = *it;
					st.erase(st.find(num2 - next));
					it--;
				}
				if (num1 != - 1 && num2 != -1)
				{
					st.insert(num2 - num1);
				}
				s.erase(it);
				x.pb(next);	
				++cnt;
			}
			else
			{
				br;
			}
		}
	}	
	for (ll num : s)
	{
		y.pb(num);
	}
	if (sz(x) == n)
	{
		cout << 1 << nl;
		cout << x[0] << nl;
		cout << sz(x) - 1 << nl;
		for (ll i = 1; i < sz(x); ++i)
		{
			cout << x[i] << ' ';
		}
		cout << nl;
		off;
	}
	if (sz(x) > 0 && sz(y) > 0)
	{
		if (sz(y) > 1)
		{
			for (ll i = 2; i < sz(y); ++i)
			{
				if (y[i] - y[i - 1] == y[1] - y[0])
				{
					cn;
				}
				rt;
			}
		}
		
		cout << sz(x) << nl;
		for (ll i = 0; i < sz(x); ++i)
		{
			cout << x[i] << ' ';
		}
		cout << nl;
		cout << sz(y) << nl;
		for (ll i = 0; i < sz(y); ++i)
		{
			cout << y[i] << ' ';
		}
		cout << nl;
		off;
	}
}

void ma1n ()
{
	cin >> n;
	for (ll i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	solve(1, 2);	
	solve(2, 3);
	solve(1, 3);
	cout << -1 << nl;
}

int main (/* You Vs You */)
{  
	qataima ();
    open ();
    int zxc = 1;
//	cin >> zxc;
    while (zxc--)	
    {
        ma1n ();
    }
    return 0;
}

Compilation message (stderr)

drvca.cpp: In function 'void open(std::string)':
drvca.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen((fname + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drvca.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen((fname + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...