답안 #1055852

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055852 2024-08-13T06:01:53 Z 근데 드레이븐이 문제에요 이 와중에 진짜 예 타워 안쪽 (#11111) Pizza Party (CCO24_day1problem2) C++17
3 / 12
454 ms 32788 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int n, a[1001001], b[1001001], r[1001001], c[1001001];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for(int i=1;i<=n;i++) cin >> a[i];
	for(int i=1;i<=n;i++) cin >> b[i];

	vector<int> A(a+1, a+1+n), B(b+1, b+1+n);
	sort(A.rbegin(), A.rend()), sort(B.rbegin(), B.rend());
	if(A != B) return cout << -1, 0;

	int mx = A[0];
	A = vector<int>(a+1, a+1+n), B = vector<int>(b+1, b+1+n);
	reverse(A.begin(), A.end());

	if(A == B) {
		cout << "1\n";
		for(int i=1;i<=n;i++) cout << 1 << " \n"[i == n];
		for(int i=1;i<=n;i++) cout << 1 << " \n"[i == n];
		return 0;
	}

	if(mx == 2) {
		cout << "2\n";
		for(int i=1;i<=n;i++) cout << a[i] << " \n"[i == n];
		for(int i=1;i<=n;i++) cout << b[i] << " \n"[i == n];
		return 0;
	}


	for(int i=1;i<=n;i++) r[b[i]] = i;

	map<int, int> mp;
	for(int i=1;i<=n;i++) {
		auto it = mp.lower_bound(r[a[i]]);

		int cur = 0;
		if(it != mp.end()) cur = it->second, mp.erase(it);
		if(!cur) cur = mp.size()+1;

		mp[r[a[i]]] = c[r[a[i]]] = cur;
	}
	
	cout << mp.size() << "\n";
	for(int i=1;i<=n;i++) cout << c[a[i]] << " \n"[i == n];
	for(int i=1;i<=n;i++) cout << c[b[i]] << " \n"[i == n];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 19984 KB good job!
2 Correct 155 ms 22028 KB good job!
3 Correct 156 ms 23992 KB good job!
4 Correct 156 ms 23948 KB good job!
5 Correct 158 ms 23996 KB good job!
6 Correct 165 ms 23888 KB good job!
7 Correct 158 ms 23996 KB good job!
8 Correct 172 ms 20240 KB good job!
9 Correct 157 ms 20412 KB good job!
10 Correct 154 ms 19980 KB good job!
11 Correct 157 ms 19988 KB good job!
12 Correct 156 ms 19980 KB good job!
13 Correct 0 ms 348 KB good job!
14 Correct 0 ms 348 KB good job!
15 Correct 0 ms 348 KB good job!
16 Correct 78 ms 16116 KB good job!
17 Correct 81 ms 15952 KB good job!
18 Correct 94 ms 15924 KB good job!
19 Correct 81 ms 16084 KB good job!
20 Correct 82 ms 15956 KB good job!
21 Correct 82 ms 15956 KB good job!
22 Correct 162 ms 19976 KB good job!
23 Correct 0 ms 348 KB good job!
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 604 KB flavours don't match
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 454 ms 32788 KB flavours don't match
2 Halted 0 ms 0 KB -