| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 198609 | leonarda | Slagalica (COCI19_slagalica2) | C++14 | 44 ms | 3576 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pi;
typedef long long int lint;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef set<int> si;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
int n;
int leftt, leftb, rightt, rigthb;
vi v[8];
int ans[maxn];
int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n;
	for(int i = 0; i < n; ++i)
	{
		int x, a;
		cin >> x >> a;
		v[x - 1].pb(a);
	}
	
	if((v[4].size() + v[5].size() != 1) or (v[6].size() + v[7].size() != 1))
		return cout << -1, 0;
	
	for(int i = 0; i < 8; ++i)
		sort(v[i].begin(), v[i].end());
		
	int leftt = v[0].size() + v[1].size() + v[6].size();
	int leftb = v[2].size() + v[3].size() + v[7].size();
	int rightt = v[0].size() + v[2].size() + v[4].size();
	int rightb = v[1].size() + v[3].size() + v[5].size();
	
	if((leftt != rightb) or (leftb != rightt))
		return cout << -1, 0;
	
	int poc, kraj; // == 0 ako je tab, == 1 ako je blank
	int curleftt = 0, curleftb = 0, currightb = 0, currightt = 0;
	int indeks[8] = {0};
	int ex; // == 0 ako je tab, == 1 ako je blank
	
	if(!v[4].empty())
	{
		poc = 0;
		ans[0] = v[4][0];
		++currightt;
		ex = 0;
	} else
	{
		poc = 1;
		ans[0] = v[5][0];
		++currightb;
		ex = 1;
	}
	
	if(!v[6].empty())
	{
		kraj = 0;
		ans[n - 1] = v[6][0];
	} else
	{
		kraj = 1;
		ans[n - 1] = v[7][0];
	}
	
	for(int i = 1; i < n - 2; ++i)
	{
		if(ex == 0)
		{
			if(kraj == 0 and currightb == rightb - 1)
			{
				ans[i] = v[2][indeks[2]];
				++indeks[2];
				++currightt;
			} else if(kraj == 1 and currightt == rightt - 1)
			{
				ans[i] = v[3][indeks[3]];
				++indeks[3];
				++currightb;
			} else
			{
				if(v[2][indeks[2]] < v[3][indeks[3]])
				{
					ans[i] = v[2][indeks[2]];
					++indeks[2];
					++currightt;
				} else 
				{
					ans[i] = v[3][indeks[3]];
					++indeks[3];
					++currightb;
				}
			} 
		} else 
		{			
			if(kraj == 0 and currightb == rightb - 1)
			{
				ans[i] = v[0][indeks[0]];
				++indeks[0];
				++currightt;
			} else if(kraj == 1 and currightt == rightt - 1)
			{
				ans[i] = v[1][indeks[1]];
				++indeks[1];
				++currightb;
			} else
			{
				if(v[20][indeks[0]] < v[1][indeks[1]])
				{
					ans[i] = v[0][indeks[0]];
					++indeks[0];
					++currightt;
				} else 
				{
					ans[i] = v[1][indeks[1]];
					++indeks[1];
					++currightb;
				}
			} 
		}
	}
	
	if(n > 2) 
	{
		if(kraj == 0 and indeks[1] != v[1].size())
			ans[n - 2] = v[1][indeks[1]];
		else if(kraj == 0 and indeks[3] != v[3].size())
			ans[n - 2] = v[3][indeks[3]];
		else if(kraj == 1 and indeks[0] != v[0].size())
			ans[n - 2] = v[0][indeks[0]];
		else
			ans[n - 2] = v[2][indeks[2]];
	}
	
	for(int i = 0; i < n; ++i)
		cout << ans[i] << " ";		
	
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
