Submission #1055856

# Submission time Handle Problem Language Result Execution time Memory
1055856 2024-08-13T06:04:22 Z 근데 드레이븐이 문제에요 이 와중에 진짜 예 타워 안쪽 (#11111) Pizza Party (CCO24_day1problem2) C++17
12 / 12
580 ms 94904 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[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];
}
# Verdict Execution time Memory Grader output
1 Correct 164 ms 19980 KB good job!
2 Correct 156 ms 20084 KB good job!
3 Correct 163 ms 20116 KB good job!
4 Correct 152 ms 19980 KB good job!
5 Correct 156 ms 19984 KB good job!
6 Correct 162 ms 19980 KB good job!
7 Correct 169 ms 19984 KB good job!
8 Correct 155 ms 20060 KB good job!
9 Correct 172 ms 19984 KB good job!
10 Correct 155 ms 19980 KB good job!
11 Correct 151 ms 19984 KB good job!
12 Correct 154 ms 20060 KB good job!
13 Correct 0 ms 344 KB good job!
14 Correct 0 ms 348 KB good job!
15 Correct 0 ms 372 KB good job!
16 Correct 84 ms 16116 KB good job!
17 Correct 81 ms 15952 KB good job!
18 Correct 95 ms 15884 KB good job!
19 Correct 79 ms 16028 KB good job!
20 Correct 78 ms 15896 KB good job!
21 Correct 79 ms 15956 KB good job!
22 Correct 157 ms 19984 KB good job!
23 Correct 0 ms 348 KB good job!
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB good job!
2 Correct 1 ms 348 KB good job!
3 Correct 2 ms 600 KB good job!
4 Correct 1 ms 348 KB good job!
5 Correct 2 ms 604 KB good job!
6 Correct 1 ms 348 KB good job!
7 Correct 1 ms 344 KB good job!
8 Correct 2 ms 604 KB good job!
9 Correct 2 ms 652 KB good job!
10 Correct 2 ms 604 KB good job!
11 Correct 2 ms 860 KB good job!
12 Correct 1 ms 348 KB good job!
13 Correct 2 ms 860 KB good job!
14 Correct 1 ms 604 KB good job!
15 Correct 1 ms 348 KB good job!
# Verdict Execution time Memory Grader output
1 Correct 441 ms 32952 KB good job!
2 Correct 203 ms 15952 KB good job!
3 Correct 437 ms 37136 KB good job!
4 Correct 217 ms 18004 KB good job!
5 Correct 440 ms 33720 KB good job!
6 Correct 211 ms 21816 KB good job!
7 Correct 217 ms 17492 KB good job!
8 Correct 438 ms 32700 KB good job!
9 Correct 448 ms 42684 KB good job!
10 Correct 453 ms 43196 KB good job!
11 Correct 580 ms 94904 KB good job!
12 Correct 291 ms 20444 KB good job!
13 Correct 578 ms 84848 KB good job!
14 Correct 361 ms 28240 KB good job!
15 Correct 223 ms 15904 KB good job!
16 Correct 215 ms 16368 KB good job!