fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27. // 2 2
  28. // cdab dcba
  29. // abcd abcd
  30.  
  31.  
  32.  
  33.  
  34. vector<string> a;
  35. vector<string> b;
  36.  
  37. vector<string> consistency(int n){
  38.  
  39. vector<string> ans(n, "No");
  40.  
  41. for(int i=0; i<n; i++){
  42. auto x = a[i];
  43. auto y = b[i];
  44.  
  45. if(x.size() != y.size()) continue;
  46. int k = x.size();
  47.  
  48. vector<int> even(26, 0), odd(26, 0);
  49.  
  50. for(int j=0; j<k; j+=2) even[x[j]-'a']++;
  51. for(int j=0; j<k; j+=2) even[y[j]-'a']--;
  52.  
  53. for(int j=1; j<k; j+=2) odd[x[j]-'a']++;
  54. for(int j=1; j<k; j+=2) odd[y[j]-'a']--;
  55.  
  56. bool isValid = true;
  57. for(int j=0; j<26; j++){
  58. if(even[j] > 0) isValid = false;
  59. if(odd[j] > 0) isValid = false;
  60. }
  61.  
  62. if(isValid) ans[i] = "Yes";
  63. }
  64.  
  65. return ans;
  66. }
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. vector<string> practice(int n){
  83.  
  84.  
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91. void solve() {
  92.  
  93. int m, n;
  94. cin>> m >> n;
  95.  
  96. a.resize(m);
  97. for(int i=0; i<m; i++) cin >> a[i];
  98.  
  99. b.resize(n);
  100. for(int i=0; i<n; i++) cin >> b[i];
  101.  
  102. auto ans = consistency(n);
  103. for(auto& t : ans) cout << t << " "; cout << endl;
  104.  
  105. }
  106.  
  107.  
  108.  
  109.  
  110.  
  111. int32_t main() {
  112. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  113.  
  114. int t = 1;
  115. // cin >> t;
  116. while (t--) {
  117. solve();
  118. }
  119.  
  120. return 0;
  121. }
Success #stdin #stdout 0s 5312KB
stdin
2 2
cdab dcba
abcd abcd
stdout
Yes No