Advertisement
7oSkaaa

Is B a subsequence of A ?

Aug 11th, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define cin(vec) for(auto& i : vec) cin >> i
  5. #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
  6. #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
  7. #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++);
  8. #define cout_map(mp) for(auto& [f, s] : mp) cout << f << "  " << s << "\n";
  9. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
  10. #define fixed(n) cout << fixed << setprecision(n)
  11. #define Ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  12. #define fill(vec, value) memset(vec, value, sizeof(vec));
  13. #define Num_of_Digits(n) ((int)log10(n)+1)
  14. #define all(vec) vec.begin(),vec.end()
  15. #define rall(vec) vec.rbegin(),vec.rend()
  16. #define sz(x) int(x.size())
  17. #define fi first
  18. #define se second
  19. #define Pair pair < int, int >
  20. #define ll long long
  21. #define ull unsigned long long
  22. #define Mod  1'000'000'007
  23. #define INF 2'000'000'000
  24. #define PI acos(-1)
  25.  
  26. void Code_Crush(){
  27.   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  28.   #ifndef ONLINE_JUDGE
  29.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  30.   #endif
  31. }
  32.  
  33. int main(){
  34.   Code_Crush();
  35.   int n, m;                                           cin >> n >> m;
  36.   vector < int > a(n), b(m);
  37.   cin(a);
  38.   cin(b);
  39.   int i = 0, j = 0;
  40.   while(i < n){
  41.     if(a[i] == b[j]) j++;
  42.     i++;
  43.   }
  44.   cout << (j == m ? "YES" : "NO");
  45.   Time
  46.   return 0;
  47. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement