Advertisement
Ahmed_Negm

Untitled

Mar 5th, 2024
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define nl "\n"
  6.  
  7. void files(){
  8.     ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
  9.     #ifndef ONLINE_JUDGE
  10.         freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  11.     #endif
  12. }
  13.  
  14.  
  15. void solve(){
  16. string s,t;
  17.     int k;
  18.     cin>>s>>k>>t;
  19.     int n = s.size();
  20.     if(n%k){
  21.         cout<<"0";
  22.         return;
  23.     }
  24.    
  25.     if((int)t.size() != n){
  26.         cout<<"0";
  27.         return;
  28.     }
  29.  
  30.     map<string,int>mp;
  31.     int d = n/k;
  32.     for(int i=0; i<n; i+=d){
  33.         string temp = s.substr(i,d);
  34.         mp[temp]++;
  35.     }
  36.  
  37.     for(int i=0;i<n;i+=d){
  38.         string temp = t.substr(i,d);
  39.         if(mp[temp]){
  40.             mp[temp]--;
  41.         }else{
  42.             cout<<"0";
  43.             return;
  44.         }
  45.     }
  46.  
  47.     for(auto&[x,y]:mp){
  48.         if(y){
  49.             cout<<"0";
  50.             return;
  51.         }
  52.     }
  53.  
  54.     cout<<"1";
  55.  
  56.  
  57. }
  58.  
  59. int main(){
  60.     files();
  61.     int t = 1;
  62.     // cin>>t;
  63.     while(t--) solve();
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement