Submission #444686

# Submission time Handle Problem Language Result Execution time Memory
444686 2021-07-14T19:11:55 Z penguinhacker Slagalica (COCI19_slagalica2) C++14
15 / 70
36 ms 3004 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN=1e5;
int n;
ar<int, 2> a[mxN];
vector<ar<int, 2>> first, last; // 0 is sticking out
deque<int> q[2][2];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i=0; i<n; ++i) {
		int x, y;
		cin >> x >> y;
		if (x==5||x==6)
			first.push_back({y, x-5});
		else if (x==7||x==8)
			last.push_back({y, (x-7)^1});
		else if (x==3||x==4)
			q[0][x==4].push_back(y);
		else
			q[1][x==2].push_back(y);
	}
	if (first.size()!=1||last.size()!=1) {
		cout << -1;
		return 0;
	}
	for (int i : {0, 1})
		for (int j : {0, 1})
			sort(q[i][j].begin(), q[i][j].end());
	vector<int> ans={first[0][0]};
	int cur=first[0][1];
	for (int i=1; i<n-1; ++i) {
		if (q[cur][0].empty()&&q[cur][1].empty()) {
			cout << -1;
			return 0;
		}
		int t;
		if (q[cur][0].empty()^q[cur][1].empty())
			t=q[cur][0].empty();
		else if (q[0][last[0][1]].size()+q[1][last[0][1]].size()>1)
			t=q[cur][1][0]<q[cur][0][0];
		else
			t=last[0][1]^1;
		assert(q[cur][t].size());
		ans.push_back(q[cur][t][0]);
		q[cur][t].pop_front();
		cur=t;
	}
	if (cur!=last[0][1]) {
		cout << -1;
	} else {
		for (int i : ans)
			cout << i << " ";
		cout << last[0][0];
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 2928 KB Output is correct
2 Correct 29 ms 2440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2912 KB Output is correct
2 Correct 29 ms 2316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2284 KB Output is correct
2 Incorrect 29 ms 2332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 2000 KB Output is correct
2 Correct 34 ms 2852 KB Output is correct
3 Incorrect 32 ms 2452 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 2068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 3004 KB Output is correct
2 Correct 29 ms 2076 KB Output is correct
3 Incorrect 31 ms 2356 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 2348 KB Output is correct
2 Incorrect 27 ms 2240 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 2436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 2272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 2484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 2240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 2248 KB Output isn't correct
2 Halted 0 ms 0 KB -