답안 #198609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198609 2020-01-26T23:02:21 Z leonarda Slagalica (COCI19_slagalica2) C++14
5 / 70
44 ms 3576 KB
#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

slagalica.cpp: In function 'int main()':
slagalica.cpp:137:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(kraj == 0 and indeks[1] != v[1].size())
                    ~~~~~~~~~~^~~~~~~~~~~~~~
slagalica.cpp:139:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   else if(kraj == 0 and indeks[3] != v[3].size())
                         ~~~~~~~~~~^~~~~~~~~~~~~~
slagalica.cpp:141:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   else if(kraj == 1 and indeks[0] != v[0].size())
                         ~~~~~~~~~~^~~~~~~~~~~~~~
slagalica.cpp:48:6: warning: variable 'poc' set but not used [-Wunused-but-set-variable]
  int poc, kraj; // == 0 ako je tab, == 1 ako je blank
      ^~~
slagalica.cpp:49:6: warning: unused variable 'curleftt' [-Wunused-variable]
  int curleftt = 0, curleftb = 0, currightb = 0, currightt = 0;
      ^~~~~~~~
slagalica.cpp:49:20: warning: unused variable 'curleftb' [-Wunused-variable]
  int curleftt = 0, curleftb = 0, currightb = 0, currightt = 0;
                    ^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 2676 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 35 ms 2628 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 2036 KB Output is correct
2 Runtime error 36 ms 2676 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 2040 KB Output is correct
2 Runtime error 33 ms 2296 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 44 ms 3060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 35 ms 2440 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2040 KB Output is correct
2 Runtime error 42 ms 2576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 37 ms 3576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 34 ms 2536 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 42 ms 2808 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 3192 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 32 ms 2932 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -