fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef unsigned long long ull;
  5. typedef long double lld;
  6. /*
  7. #include <ext/pb_ds/assoc_container.hpp>
  8. #include <ext/pb_ds/tree_policy.hpp>
  9. using namespace __gnu_pbds;
  10.  
  11. template<class T> using ordered_set =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
  12. // ordered_set.find_by_order(k) returns the iterator to kth element
  13. // ordered_set.order_of_key(k) returns the number of elements strictly less than k
  14.  
  15. (FOR ORDERED MULTISET "UPPER_BOUND" AND "LOWER_BOUND" ARE REVERSED)
  16. template<class T> using ordered_multiset =tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
  17. // ordered_set.find_by_order(k) returns the iterator to kth element
  18. // ordered_set.order_of_key(k) returns the number of elements strictly less than k
  19. */
  20. #ifdef LOCALIO
  21. #define dbg(...) cerr<< __VA_ARGS__;
  22. #define dbgl(...) cerr<< __VA_ARGS__<<nl;
  23. #else
  24. #define dbg(...) ;
  25. #define dbgl(...) ;
  26. #endif
  27. #define fastio ios_base::sync_with_stdio(0); cin.tie(0);
  28. #define all(x) x.begin(),x.end()
  29. #define nl '\n'
  30. #define pb(x) push_back(x)
  31. #define sz(x) (int)x.size()
  32. #define szl(x) (long long)x.size()
  33.  
  34. // const int mod = 998244353;
  35. const int mod = 1e9+7;
  36.  
  37.  
  38.  
  39. void solve()
  40. {
  41. int n; cin>>n;
  42. int a[n],b[n];
  43. for(auto &i:a) cin>>i;
  44. for(auto &i:b) cin>>i;
  45.  
  46. int pre[n],suf[n];
  47.  
  48. pre[0] = 1;
  49. for(int i=1; i<n; ++i) pre[i] = (b[i]==b[i-1])?pre[i-1]:pre[i-1]+1;
  50. pre[0] = (a[0]==b[0])?0:1;
  51. for(int i=1; i<n; ++i) pre[i] = (a[i]==b[i]?pre[i-1]:pre[i]);
  52.  
  53.  
  54. reverse(a,a+n);
  55. reverse(b,b+n);
  56.  
  57. suf[0] = 1;
  58. for(int i=1; i<n; ++i) suf[i] = (b[i]==b[i-1])?suf[i-1]:suf[i-1]+1;
  59. suf[0] = (a[0]==b[0])?0:1;
  60. for(int i=1; i<n; ++i) suf[i] = (a[i]==b[i]?suf[i-1]:suf[i]);
  61.  
  62. reverse(suf,suf+n);
  63.  
  64.  
  65. int ans = min(suf[0],pre[n-1]);
  66.  
  67. for(int i=1; i<n; ++i)
  68. {
  69. ans = min(ans,pre[i-1]+suf[i]);
  70. }
  71.  
  72.  
  73. cout<<ans<<nl;
  74.  
  75.  
  76.  
  77. }
  78.  
  79. signed main() {
  80. fastio;
  81. #ifdef LOCALIO
  82. freopen("error.txt", "w", stderr);
  83. #endif
  84. int t=1;
  85. // cin>>t;
  86. while(t--)
  87. {
  88. solve();
  89. }
  90. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
0