Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 2975.cpp
- */
- using namespace std;
- #include <algorithm>
- #include <cctype>
- #include <cmath>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <iostream>
- #include <map>
- #include <queue>
- #include <set>
- #include <sstream>
- #include <stack>
- #include <string>
- #include <vector>
- #define EPS 1e-11
- #define inf ( 1LL << 31 ) - 1
- #define LL long long
- #define _rep( i, a, b, x ) for( __typeof(b) i = ( a ); i <= ( b ); i += x )
- #define rep( i, n ) _rep( i, 0, n - 1, 1 )
- #define rrep( i, a, b ) for( __typeof(b) i = ( a ); i >= ( b ); --i )
- #define xrep( i, a, b ) _rep( i, a, b, 1 )
- #define foreach(it,a) for( typeof(( a ).begin()) it=( a ).begin();it!=( a ).end();it++)
- #define abs(x) (((x)< 0) ? (-(x)) : (x))
- #define all(x) (x).begin(), (x).end()
- #define ms(x, a) memset((x), (a), sizeof(x))
- #define mp make_pair
- #define pb push_back
- #define sz(k) (int)(k).size()
- typedef vector <int> vi;
- char line[256];
- int A[256][256];
- int main()
- {
- #ifdef Local
- freopen("/home/wasi/Desktop/input.txt", "r", stdin);
- #endif
- int t, r, c;
- scanf("%d", &t);
- while (t--)
- {
- scanf("%d %d", &r, &c);
- int val;
- rep(i,r)
- {
- scanf("%s", line);
- rep(j,c)
- {
- rep(k,5) if ("BJHYN"[k] == line[j]) val = k+1;
- A[i][j] = val;
- }
- }
- int ans = 0;
- rep(i,r)
- {
- xrep(j,i+1,r-1)
- {
- int fc[5] = {0};
- rep(k, c) if (A[i][k] == A[j][k]) fc[A[i][k]-1]++;
- rep(k, 5) if (fc[k] > 1) ans += fc[k] * (fc[k]-1) / 2;
- }
- }
- cout << ans << endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment