fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define Mod 1000000007
  5. #define Max 1000001
  6. #define vt vector<long long>
  7.  
  8. void func(){
  9. ll n;
  10. cin>>n;
  11. ll a[n];
  12. ll b[n];
  13. unordered_map<ll, ll>ma, mb;
  14. for(int i=0; i<n; i++){
  15.  
  16. cin>>a[i];
  17. ma[a[i]]++;
  18. }
  19. for(int i=0; i<n; i++){
  20. cin>>b[i];
  21. mb[b[i]]++;
  22. }
  23. vector<ll>v;
  24. ll i=0;
  25. ll j=n-1;
  26.  
  27. while(true){
  28. ll s=v.size();
  29. if(s==n)
  30. {
  31. break;
  32. }
  33. if(a[i]!=b[j] && mb[b[j]]!=0){
  34. v.push_back(b[j]);
  35. mb[b[j]]--;
  36. i++;
  37. j--;
  38. }
  39. else if(a[i]==b[j]){
  40. bool ok=false;
  41. for(int k=0; k<n; k++){
  42. if(a[i]!=b[k] && mb[b[k]]!=0){
  43. v.push_back(b[k]);
  44. mb[b[k]]--;
  45. ok=true;
  46. break;
  47. }
  48. }
  49. if(!ok){
  50. cout<<"No"<<endl;
  51. return;
  52. }
  53. i++;
  54. }
  55. else if(a[i]!=b[j] && mb[b[j]]==0){
  56. bool ok=false;
  57. for(int k=0; k<n; k++){
  58. if(a[i]!=b[k] && mb[b[k]]!=0){
  59. v.push_back(b[k]);
  60. mb[b[k]]--;
  61. ok=true;
  62. break;
  63. }
  64. }
  65. if(!ok){
  66. cout<<"No"<<endl;
  67. return;
  68. }
  69. i++;
  70. }
  71. }
  72. cout<<"Yes"<<endl;
  73. for(auto i: v){
  74. cout<<i<<" ";
  75. }
  76. cout<<endl;
  77. }
  78.  
  79. int main(){
  80.  
  81. ios_base::sync_with_stdio(false);
  82. cin.tie(NULL);
  83. cout.tie(NULL);
  84.  
  85.  
  86. //
  87. // int t;
  88. // cin >> t;
  89. // for(ll i=1; i<=t; i++)
  90. // {
  91. func();
  92. // cout<<endl;
  93. //cout<<func()<<endl;
  94.  
  95. //if(func())
  96. // cout<<"Yes"<< endl;
  97. //else
  98. // cout <<"No"<<endl;
  99. //cout<<"Case"<<" "<<"#"<<i<<":"<<" "<<func()<<endl;
  100. // }
  101. return 0;
  102. }
Success #stdin #stdout 0s 4496KB
stdin
Standard input is empty
stdout
Yes