Ankit_132

C

Sep 16th, 2023
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int m;
  8.     cin>>m;
  9.  
  10.     vector<string> s(3);
  11.     cin>>s[0]>>s[1]>>s[2];
  12.  
  13.     for(auto &e: s)
  14.         e = e+e+e;
  15.  
  16.     int ans = 1e9;
  17.  
  18.     for(int i=0; i<3*m; i++)
  19.     {
  20.         for(int j=0; j<3*m; j++)
  21.         {
  22.             for(int k=0; k<3*m; k++)
  23.             {
  24.                 if(i==j || j==k || i==k)        continue;
  25.  
  26.                 if(s[0][i]!=s[1][j] || s[1][j]!=s[2][k] || s[0][i]!=s[2][k])        continue;
  27.  
  28.                 ans = min(ans, max({i, j, k}));
  29.             }
  30.         }
  31.     }
  32.  
  33.     if(ans == 1e9)      ans = -1;
  34.  
  35.     cout<<ans<<"\n";
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment