Submission #495973

# Submission time Handle Problem Language Result Execution time Memory
495973 2021-12-20T08:54:51 Z Nimbostratus Slagalica (COCI19_slagalica2) C++17
10 / 70
33 ms 4260 KB
#include "bits/stdc++.h"
#define endl '\n'
#define fi first
#define se second
constexpr int maxn = 2e5 + 5;
constexpr int inf = 2e9;
constexpr int mod = 1e9 + 7;
using namespace std;
using lint = long long;
using pii = pair<int, int>;

int n;
int typ[maxn], a[maxn];
vector<int> v[10];
vector<int> ans;
int typl, typr, al, ar;

signed main() {
	#ifdef Local
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> typ[i] >> a[i];
		typl = typ[i] == 5 || typ[i] == 6 ? typ[i] : typl;
		al = typ[i] == 5 || typ[i] == 6 ? a[i] : al;
		typr = typ[i] == 7 || typ[i] == 8 ? typ[i] : typr;
		ar = typ[i] == 7 || typ[i] == 8 ? a[i] : ar; 
		v[typ[i]].push_back(a[i]);
	}
	for(int i = 1; i <= 8; i++)
		sort(v[i].begin(), v[i].end(), greater<int>());
	bool bad = false;
	bad |= typl == 5 && typr == 7 && v[4].empty();
	bad |= typl == 6 && typr == 8 && v[1].empty();
	bad |= typl == 5 && typr == 8 && v[4].size() != v[1].size();
	bad |= typl == 6 && typr == 7 && v[4].size() != v[1].size();
	if(bad) {
		cout << -1 << endl;
		return 0;
	}
	int toput = typl - 5;
	ans.push_back(al);
	while(ans.size() < n - 1) {
		if(toput == 1) {
			if(v[2].empty() || (v[1].size() != 1 && v[2].back() < v[1].back())) {
				ans.push_back(v[1].back());
				v[1].pop_back();
				toput = 0;
			}
			else {
				ans.push_back(v[2].back());
				v[2].pop_back();
				toput = 1;
			}
		}
		else {
			if(v[3].empty() || (v[4].size() != 1 && v[4].back() < v[3].back())) {
				ans.push_back(v[4].back());
				v[4].pop_back();
				toput = 1;
			}
			else {
				ans.push_back(v[3].back());
				v[3].pop_back();
				toput = 0;
			}
		}
	}
	ans.push_back(ar);
	for(int x : ans)
		cout << x << " ";
	cout << endl;
}

Compilation message

slagalica.cpp: In function 'int main()':
slagalica.cpp:47:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |  while(ans.size() < n - 1) {
      |        ~~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 3756 KB Output is correct
2 Incorrect 31 ms 3888 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 3460 KB Output is correct
2 Correct 22 ms 2568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2796 KB Output is correct
2 Runtime error 22 ms 4260 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2412 KB Output is correct
2 Runtime error 23 ms 3636 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 23 ms 4064 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 20 ms 3604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 3752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 4160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 3560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 4156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 3644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 3612 KB Output isn't correct
2 Halted 0 ms 0 KB -