Submission #1055773

# Submission time Handle Problem Language Result Execution time Memory
1055773 2024-08-13T05:13:07 Z d(#11110) Pizza Party (CCO24_day1problem2) C++17
0 / 12
542 ms 84816 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
using pii=array<int,2>;
using tii=array<int,3>;
const int N=1000005;
int n,a[N],b[N],cnt[N],k,ans[N];
tii v[N];
set<pii,greater<pii>> S;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		cnt[a[i]]++;
		v[a[i]][0]=i;
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
		cnt[b[i]]--;
		if(cnt[b[i]]<0){
			cout<<"-1\n";
			return 0;
		}
		v[b[i]][1]=n+1-i;
	}
	for(int i=1;i<=n;i++) v[i][2]=i;
	sort(v+1,v+n+1);
	for(int i=1;i<=n;i++){
		int val=v[i][1];
		auto iter=S.lower_bound({val,-1});
		if(iter==S.end()){
			k++;
			S.insert({val,k});
			ans[v[i][2]]=k;
			continue;
		}
		int g=(*iter)[1];
		S.erase(iter);
		S.insert({val,g});
		ans[v[i][2]]=g;
	}
	reverse(a+1,a+n+1);
	cout<<k<<"\n";
	for(int i=1;i<=n;i++) cout<<ans[a[i]]<<" \n"[i==n];
	for(int i=1;i<=n;i++) cout<<ans[b[i]]<<" \n"[i==n];
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 538 ms 84816 KB flavours don't match
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 604 KB flavours don't match
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 542 ms 36692 KB flavours don't match
2 Halted 0 ms 0 KB -