Guest User

Untitled

a guest
Mar 6th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. /*
  2.  *      2975.cpp
  3.  */
  4.  
  5. using namespace std;
  6.  
  7. #include <algorithm>
  8. #include <cctype>
  9. #include <cmath>
  10. #include <cstdio>
  11. #include <cstdlib>
  12. #include <cstring>
  13. #include <iostream>
  14. #include <map>
  15. #include <queue>
  16. #include <set>
  17. #include <sstream>
  18. #include <stack>
  19. #include <string>
  20. #include <vector>
  21.  
  22. #define EPS 1e-11
  23. #define inf ( 1LL << 31 ) - 1
  24. #define LL long long
  25.  
  26. #define _rep( i, a, b, x ) for( __typeof(b) i = ( a ); i <= ( b ); i += x )
  27. #define rep( i, n ) _rep( i, 0, n - 1, 1 )
  28. #define rrep( i, a, b ) for( __typeof(b) i = ( a ); i >= ( b ); --i )
  29. #define xrep( i, a, b ) _rep( i, a, b, 1 )
  30. #define foreach(it,a) for( typeof(( a ).begin()) it=( a ).begin();it!=( a ).end();it++)
  31.  
  32. #define abs(x) (((x)< 0) ? (-(x)) : (x))
  33. #define all(x) (x).begin(), (x).end()
  34. #define ms(x, a) memset((x), (a), sizeof(x))
  35. #define mp make_pair
  36. #define pb push_back
  37. #define sz(k) (int)(k).size()
  38.  
  39. typedef vector <int> vi;
  40.  
  41. char line[256];
  42. int A[256][256];
  43. int main()
  44. {
  45.     #ifdef Local
  46.         freopen("/home/wasi/Desktop/input.txt", "r", stdin);
  47.     #endif
  48.     int t, r, c;
  49.     scanf("%d", &t);
  50.     while (t--)
  51.     {
  52.         scanf("%d %d", &r, &c);
  53.         int val;
  54.         rep(i,r)
  55.         {
  56.             scanf("%s", line);
  57.             rep(j,c)
  58.             {
  59.                 rep(k,5) if ("BJHYN"[k] == line[j]) val = k+1;
  60.                 A[i][j] = val;
  61.             }
  62.         }
  63.        
  64.         int ans = 0;
  65.        
  66.         rep(i,r)
  67.         {
  68.             xrep(j,i+1,r-1)
  69.             {
  70.                 int fc[5] = {0};
  71.                 rep(k, c) if (A[i][k] == A[j][k]) fc[A[i][k]-1]++;
  72.                 rep(k, 5) if (fc[k] > 1) ans += fc[k] * (fc[k]-1) / 2;
  73.             }
  74.         }
  75.        
  76.         cout << ans << endl;
  77.        
  78.     }
  79.     return 0;
  80. }
Add Comment
Please, Sign In to add comment