# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1055741 |
2024-08-13T04:44:44 Z |
정희우(#11069) |
Pizza Party (CCO24_day1problem2) |
C++17 |
|
349 ms |
32592 KB |
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
using lint = long long;
using vint = vector<int>;
using pii = pair<int,int>;
const int MAX_N=1000010;
int n;
int a[MAX_N],b[MAX_N];
int cnt[MAX_N];
int col[MAX_N][3];
set<pii> st;
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n;
int mx=0;
for(int i=0;i<n;i++)
{
cin >> a[i];
cnt[a[i]]++;
mx=max(mx,a[i]);
col[a[i]][0]=i;
}
for(int i=0;i<n;i++)
{
cin >> b[i];
cnt[b[i]]--;
col[b[i]][1]=i;
}
for(int i=1;i<=n;i++)
if(cnt[i]!=0)
{
cout << -1;
return 0;
}
if(mx<=2)
{
int flag=1;
for(int i=0;i<n;i++)
if(a[i]!=b[n-1-i])flag=0;
if(flag)
{
cout << "1\n";
for(int t=0;t<2;t++,cout << '\n')
for(int i=0;i<n;i++)cout << "1 ";
}
else
{
cout << "2\n";
for(int i=0;i<n;i++)cout << a[i] << ' ';
cout << '\n';
for(int i=0;i<n;i++)cout << b[i] << ' ';
}
return 0;
}
int k=0;
for(int i=0;i<n;i++)
{
int o=col[a[i]][1];
auto it=st.lower_bound({o,0});
if(it==st.end())
{
col[a[i]][2]=++k;
st.insert({o,k});
}
else
{
col[a[i]][2]=it->second;
st.erase(it);
st.insert({o,col[a[i]][2]});
}
}
cout << k << '\n';
for(int i=0;i<n;i++)cout << col[a[i]][2] << ' ';
cout << '\n';
for(int i=0;i<n;i++)cout << col[b[i]][2] << ' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
121 ms |
15316 KB |
Expected EOLN |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
6492 KB |
Expected EOLN |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
349 ms |
32592 KB |
Expected EOLN |
2 |
Halted |
0 ms |
0 KB |
- |