text
stringlengths 49
983k
|
|---|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
map<string, int> used;
vector<string> a;
int n, k;
char get_c(char c1, char c2) {
if (c1 == c2) return c1;
if (c1 > c2) {
char t = c1;
c1 = c2;
c2 = t;
}
if (c1 == 'E' && c2 == 'S') return 'T';
if (c1 == 'E' && c2 == 'T') return 'S';
return 'E';
}
void solve() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
a.push_back(s);
used[s] = i;
}
map<string, int>::iterator it;
int cnt = 0;
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++) {
string s1 = a[i], s2 = a[j];
char s[100];
for (int t = 0; t < k; t++) {
s[t] = get_c(s1[t], s2[t]);
}
s[k] = 0;
string ss = s;
it = used.find(ss);
if (it != used.end() && it->second > j) cnt++;
}
cout << cnt;
}
int main() { solve(); }
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
vector<string> a(n);
unordered_set<string> s;
for (int i = 0; i < n; ++i) {
cin >> a[i];
s.insert(a[i]);
}
long long ans = 0;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
if (i == j) continue;
string t;
for (int l = 0; l < k; ++l) {
if (a[i][l] == a[j][l])
t += a[i][l];
else {
if (a[i][l] == 'S' && a[j][l] == 'E' ||
a[i][l] == 'E' && a[j][l] == 'S') {
t += 'T';
continue;
}
if (a[i][l] == 'S' && a[j][l] == 'T' ||
a[i][l] == 'T' && a[j][l] == 'S') {
t += 'E';
continue;
}
if (a[i][l] == 'E' && a[j][l] == 'T' ||
a[i][l] == 'T' && a[j][l] == 'E') {
t += 'S';
continue;
}
}
}
ans += s.count(t);
if (t == a[i]) ans--;
if (t == a[j]) ans--;
}
cout << ans / 6;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
{ solve(), cout << endl; }
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, mm, ans = 0;
cin >> n >> mm;
string a[n];
map<string, int> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string s = "";
for (int k = 0; k < mm; k++) {
char c = a[i][k], d = a[j][k];
if (c == d)
s += c;
else {
if (!(c == 'S' || d == 'S')) s += 'S';
if (!(c == 'T' || d == 'T')) s += 'T';
if (!(c == 'E' || d == 'E')) s += 'E';
}
}
if (a[i] == a[j]) {
if (m.count(s) > 2) ans++;
} else {
if (m.count(s)) ans++;
}
}
m[a[i]]++;
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
string construct(string &s, string &t) {
long long i;
string res = "";
string c = "SET";
for (i = 0; i < s.length(); i++) {
if (s[i] == t[i])
res += s[i];
else {
for (auto j : c) {
if (s[i] != j && t[i] != j) res += j;
}
}
}
return res;
}
int32_t main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long i, j;
long long n, k;
cin >> n >> k;
unordered_map<string, long long> ump;
ump.reserve(n + 1);
vector<string> lav;
for (i = 0; i < n; i++) {
string s;
cin >> s;
lav.push_back(s);
ump[s]++;
}
long long ans = 0;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (lav[i] == lav[j]) {
ans += ump[lav[i]] - 2;
} else {
ans += ump[construct(lav[i], lav[j])];
}
}
}
cout << ans / 3 << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<char> a[1505];
int N, K;
map<vector<char>, int> ma;
signed main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("A.INP", "r")) {
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
}
if (fopen(""
".in",
"r")) {
freopen(
""
".in",
"r", stdin);
freopen(
""
".out",
"w", stdout);
}
cin >> N >> K;
for (int i = 1; i <= N; ++i) {
a[i].resize(K);
for (int j = 0; j < K; ++j) {
cin >> a[i][j];
}
}
long long res = 0;
for (int i = 1; i <= N; ++i) {
ma.clear();
for (int j = N - 1; j > i; --j) {
ma[a[j + 1]]++;
vector<char> need(K);
for (int k = 0; k < K; ++k) {
if (a[i][k] == a[j][k])
need[k] = a[i][k];
else {
vector<char> val = {'S', 'E', 'T'};
for (int t = 0; t < 3; ++t) {
if (val[t] != a[i][k] && val[t] != a[j][k]) need[k] = val[t];
}
}
}
res += ma[need];
}
}
cout << res << '\n';
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long inf = 1e9;
const long long mod = 1e9 + 7;
const long long modx = 998244353;
const long long per = 666013;
long long n, k, ans;
map<string, long long> q;
string s[1505];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cerr.tie(0);
cout.tie(0);
srand(chrono::steady_clock::now().time_since_epoch().count());
cin >> n >> k;
for (long long i = 1; i <= n; i++) cin >> s[i];
q[s[1]]++;
for (long long i = 2; i < n; i++) {
for (long long j = i + 1; j <= n; j++) {
string tz = "";
for (long long t = 0; t < k; t++) {
if (s[i][t] == s[j][t])
tz.push_back(s[i][t]);
else {
if (s[i][t] == 'S' && s[j][t] == 'E') tz.push_back('T');
if (s[i][t] == 'E' && s[j][t] == 'S') tz.push_back('T');
if (s[i][t] == 'S' && s[j][t] == 'T') tz.push_back('E');
if (s[i][t] == 'T' && s[j][t] == 'S') tz.push_back('E');
if (s[i][t] == 'T' && s[j][t] == 'E') tz.push_back('S');
if (s[i][t] == 'E' && s[j][t] == 'T') tz.push_back('S');
}
}
ans += q[tz];
}
q[s[i]]++;
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, k;
char s[1500 + 5][30 + 5];
set<long long> u;
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) {
scanf("%s", s[i]);
long long sum = 0;
for (int j = 0; j < k; ++j) {
int opt;
if (s[i][j] == 'S') opt = 0;
if (s[i][j] == 'E') opt = 1;
if (s[i][j] == 'T') opt = 2;
sum = sum * 3 + opt;
}
u.insert(sum);
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
long long sum = 0;
for (int p = 0; p < k; ++p) {
char c;
if (s[i][p] == s[j][p])
c = s[i][p];
else
c = 'S' + 'E' + 'T' - s[i][p] - s[j][p];
int opt;
if (c == 'S') opt = 0;
if (c == 'E') opt = 1;
if (c == 'T') opt = 2;
sum = sum * 3 + opt;
}
if (u.count(sum)) ++ans;
}
}
printf("%d", ans / 3);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string sub;
for (int i = 0; i < k; i++) {
sub.push_back('k');
}
long long int count = 0;
set<string> arra;
for (int i = 0; i < n; i++) {
string a;
cin >> a;
arra.insert(a);
}
set<string>::iterator it1, it2;
for (it1 = arra.begin(); it1 != arra.end(); it1++) {
for (it2 = arra.begin(); it2 != arra.end(); it2++) {
string a = *it1;
string b = *it2;
if (a != b) {
for (int i = 0; i < k; i++) {
if (a[i] == b[i]) {
sub[i] = a[i];
} else if ((a[i] == 'S' && b[i] == 'T') ||
(a[i] == 'T' && b[i] == 'S')) {
sub[i] = 'E';
} else if ((a[i] == 'S' && b[i] == 'E') ||
(a[i] == 'E' && b[i] == 'S')) {
sub[i] = 'T';
} else if ((a[i] == 'E' && b[i] == 'T') ||
(a[i] == 'T' && b[i] == 'E')) {
sub[i] = 'S';
}
}
if (arra.find(sub) != arra.end()) {
count++;
}
}
}
}
cout << count / 6 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long arr[2000000] = {0}, brr[2000000] = {0};
vector<string> vec;
string str;
long long mod = 1000000007;
unordered_map<string, long long> ump;
map<char, long long> mp;
map<string, long long> mp1;
map<long long, char> rmp;
set<long long> st;
stack<long long> stk;
long long fac(long long n) {
long long i, prod = 1;
for (i = 1; i <= n; i++) prod = ((i % mod) * (prod % mod)) % mod;
return prod;
}
long long power(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long gcd(long long a, long long b) {
if (a == 0) return b;
return gcd(b % a, a);
}
long long whitecnt(long long x1, long long y1, long long x2, long long y2) {
if (x1 == x2 && y1 == y2) {
if ((x1 + y1) % 2 == 0)
return 1;
else
return 0;
}
if (((x2 - x1 + 1) * (y2 - y1 + 1)) % 2 == 0)
return ((x2 - x1 + 1) * (y2 - y1 + 1)) / 2;
else {
if ((x1 + y1) % 2 == 0)
return ((x2 - x1 + 1) * (y2 - y1 + 1)) / 2 + 1;
else
return ((x2 - x1 + 1) * (y2 - y1 + 1)) / 2;
}
}
void intersect(long long x1, long long y1, long long x2, long long y2,
long long x3, long long y3, long long x4, long long y4,
vector<long long>& tempvec) {
long long x5 = max(x1, x3);
long long y5 = max(y1, y3);
long long x6 = min(x2, x4);
long long y6 = min(y2, y4);
if (x5 <= x6 && y5 <= y6) {
tempvec.push_back(x5);
tempvec.push_back(y5);
tempvec.push_back(x6);
tempvec.push_back(y6);
}
}
string func(string str1, string str2, long long k) {
string tempstr = "";
for (long long i = 0; i < k; i++) {
if (str1[i] != str2[i])
tempstr += rmp[3 - (mp[str1[i]] + mp[str2[i]])];
else
tempstr += str1[i];
}
return tempstr;
}
int main() {
long long x, y, i, j, k, n, m, num, temp, fn,
cnt = 0, d, l, r, flag = 0, sum1 = 0, a, b, len1 = 0, t, mx = LLONG_MIN,
mn = LLONG_MAX, ind;
long long x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6;
string tempstr;
scanf("%lld %lld", &n, &len1);
mp['E'] = 0;
mp['S'] = 1;
mp['T'] = 2;
rmp[0] = 'E';
rmp[1] = 'S';
rmp[2] = 'T';
for (i = 0; i < n; i++) {
cin >> str;
vec.push_back(str);
ump[str]++;
mp1[str] = i;
}
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n - 1; j++) {
tempstr = func(vec[i], vec[j], len1);
if (ump.find(tempstr) != ump.end() && mp1[tempstr] > j) cnt++;
}
}
for (auto x : ump) {
num = x.second;
cnt += (num * (num - 1) * (num - 2)) / 6;
}
printf("%lld\n", cnt);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline char dif(char a, char b) {
if (a == 'E' && b == 'S' or b == 'E' && a == 'S') return 'T';
if (a == 'E' and b == 'T' or b == 'E' and a == 'T') return 'S';
if (a == 'S' and b == 'T' or b == 'S' and a == 'T') return 'E';
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin.exceptions(cin.failbit);
int n, k;
cin >> n >> k;
string cards[n];
for (int i = 0; i < (n); ++i) cin >> cards[i];
sort(cards, cards + n);
int ans = 0;
for (int i = 0; i < (n - 1); ++i) {
for (int j = i + 1; j < (n); ++j) {
string tofind = "";
for (int x = 0; x < (k); ++x) {
if (cards[i][x] == cards[j][x])
tofind += cards[i][x];
else
tofind += dif(cards[i][x], cards[j][x]);
}
if (binary_search(cards + j, cards + n, tofind)) ans++;
}
}
cout << ans << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
string s;
set<string> card_bank;
std::vector<string> cards;
std::map<int, char> diff_feat;
diff_feat['S' + 'T'] = 'E';
diff_feat['S' + 'E'] = 'T';
diff_feat['E' + 'T'] = 'S';
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> s;
cards.push_back(s);
card_bank.insert(s);
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string aux_card = "";
for (int feat = 0; feat < k; feat++) {
char i_feat = cards[i][feat];
char j_feat = cards[j][feat];
if (i_feat == j_feat)
aux_card += i_feat;
else
aux_card += diff_feat[(i_feat + j_feat)];
}
if (card_bank.find(aux_card) != card_bank.end()) ans++;
}
}
printf("%d\n", ans / 3);
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int maxn = 1500 + 10;
const long long linf = 1e18;
const int inf = 0x3f3f3f3f;
long long qpow(long long a, long long b) {
return b ? ((b & 1) ? a * qpow(a * a % MOD, b >> 1) % MOD
: qpow(a * a % MOD, b >> 1)) %
MOD
: 1;
}
long long qpow(long long a, long long b, long long c) {
return b ? ((b & 1) ? a * qpow(a * a % MOD, b >> 1) % c
: qpow(a * a % MOD, b >> 1)) %
c
: 1;
}
inline int ird() {
register int x = 0, f = 1;
register char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return x * f;
}
inline long long lrd() {
register long long x = 0, f = 1;
register char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return x * f;
}
int gcd(int a, int b) { return (b > 0) ? gcd(b, a % b) : a; }
string s[maxn];
int main() {
int n, m;
cin >> n >> m;
map<string, int> mp;
for (int i = 1; i <= n; i++) {
cin >> s[i];
mp[s[i]]++;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
string t;
for (int l = 0; l < m; l++) {
if (s[i][l] == s[j][l])
t += s[i][l];
else
t += 'S' + 'E' + 'T' - s[i][l] - s[j][l];
}
if (mp[t]) ans++;
}
}
cout << ans / 3 << endl;
return 0;
}
|
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
FILE* _fin = stdin;
FILE* _fout = stdout;
void reversei(int* data, int n) {
int k = n >> 1;
for (int i = 0; i < k; ++i) {
int tmp = data[i];
data[i] = data[n - i - 1];
data[n - i - 1] = tmp;
}
}
int bsearch(int val, int* data, int n) {
if (data[0] > val) return -1;
if (data[n - 1] < val) return n;
int l = 0;
int r = n - 1;
for (; l < r;) {
int mid = (l + r + 1) >> 1;
if (data[mid] <= val)
l = mid;
else
r = mid - 1;
}
if (data[r] != val) ++r;
return r;
}
struct Veci {
int* data;
int size;
int n;
};
void init(Veci* t, int size) {
t->data = (int*)malloc(sizeof(int) * size);
t->size = size;
t->n = 0;
}
void resize(Veci* t) {
int ns = t->size * 1.2f;
t->data = (int*)realloc(t->data, sizeof(int) * ns);
t->size = ns;
}
void add(Veci* t, int val) {
if (t->n >= t->size) resize(t);
int k = t->n;
t->data[k] = val;
t->n = k + 1;
}
void free(Veci* t) {
free(t->data);
*t = {0};
}
struct Vecll {
long long* data;
int size;
int n;
};
void init(Vecll* t, int size) {
t->data = (long long*)malloc(sizeof(long long) * size);
t->size = size;
t->n = 0;
}
void resize(Vecll* t) {
int ns = t->size * 1.2f;
t->data = (long long*)realloc(t->data, sizeof(long long) * ns);
t->size = ns;
}
void add(Vecll* t, long long val) {
if (t->n >= t->size) resize(t);
int k = t->n;
t->data[k] = val;
t->n = k + 1;
}
void free(Vecll* t) {
free(t->data);
*t = {0};
}
struct Vecs {
char** data;
int size;
int n;
};
void init(Vecs* t, int size) {
t->data = (char**)malloc(sizeof(char*) * size);
t->size = size;
t->n = 0;
}
void resize(Vecs* t) {
int ns = t->size * 1.2f;
t->data = (char**)realloc(t->data, sizeof(char*) * ns);
t->size = ns;
}
void add(Vecs* t, char* val) {
if (t->n >= t->size) resize(t);
int k = t->n;
t->data[k] = val;
t->n = k + 1;
}
void free(Vecs* t) {
free(t->data);
*t = {0};
}
int ispali(int* a, int* b, int n) {
for (int i = 0; i < n; ++i) {
if (a[i] != b[n - i - 1]) {
return 0;
}
}
return 1;
}
int ispalc(char* a, char* b, int n) {
for (int i = 0; i < n; ++i) {
if (a[i] != b[n - i - 1]) {
return 0;
}
}
return 1;
}
struct Pairi {
int x, y;
};
int cmp_Pairi(const void* _a, const void* _b) {
Pairi* a = (Pairi*)_a;
Pairi* b = (Pairi*)_b;
if (a->x == b->x) {
if (a->y < b->y)
return -1;
else
return 1;
}
if (a->x < b->x)
return -1;
else
return 1;
}
void sort_Pairi(Pairi* d, int n) { qsort(d, n, sizeof(Pairi), cmp_Pairi); }
int cmp_Str(const void* _a, const void* _b) {
char* a = *((char**)_a);
char* b = *((char**)_b);
return strcmp(a, b);
}
void sort_Str(char** str, int n) { qsort(str, n, sizeof(char*), cmp_Str); }
int main() {
{
_fin = fopen("data1287B.txt", "r");
if (_fin == NULL) _fin = stdin;
};
int n, k;
fscanf(_fin, "%d", &n);
fscanf(_fin, "%d", &k);
char** s = (char**)malloc(sizeof(char*) * 1501);
for (int i = 0; i < n; ++i) {
s[i] = (char*)malloc(sizeof(char) * 31);
for (;;) {
fgets(s[i], 31, _fin);
if (s[i][0] != '\n') break;
};
s[i][k] = 0;
}
sort_Str(s, n);
long long count = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
static char tmp[31];
for (int c = 0; c < k; ++c) {
if (s[i][c] == s[j][c])
tmp[c] = s[i][c];
else {
char a = s[i][c];
char b = s[j][c];
if (a > b) {
char t = a;
a = b;
b = t;
};
if (a == 'E' && b == 'S')
tmp[c] = 'T';
else if (a == 'E' && b == 'T')
tmp[c] = 'S';
else if (a == 'S' && b == 'T')
tmp[c] = 'E';
}
}
tmp[k] = 0;
int left = j + 1;
int right = n - 1;
while (left < right) {
int mid = (left + right + 1) >> 1;
if (strcmp(s[mid], tmp) <= 0)
left = mid;
else
right = mid - 1;
}
if (strcmp(s[right], tmp) == 0) {
count++;
}
}
}
fprintf(_fout, "%lld\n", count);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
vector<string> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
unordered_map<string, int> mp;
for (int i = 0; i < n; i++) {
mp[v[i]] = i;
}
long long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string get = "";
for (int t = 0; t < k; t++) {
if (v[i][t] == v[j][t]) {
get += v[i][t];
} else {
if (v[i][t] == 'S') {
if (v[j][t] == 'E') {
get += 'T';
} else {
get += 'E';
}
} else if (v[i][t] == 'E') {
if (v[j][t] == 'S') {
get += 'T';
} else {
get += 'S';
}
} else {
if (v[j][t] == 'S') {
get += 'E';
} else {
get += 'S';
}
}
}
}
if (mp[get] > j) {
ans++;
}
}
}
cout << ans << "\n";
return;
}
signed main() {
auto start = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
solve();
}
auto stop = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(long long &x, long long y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(long long &x, long long y) { return (y > x) ? x = y, 1 : 0; }
using namespace std;
vector<string> c;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.precision(20);
int n, k;
cin >> n >> k;
c.resize(n);
for (int i = (0); i < (n); ++i) cin >> c[i];
sort(c.begin(), c.end());
long long ans = 0;
for (int i = (0); i < (n); ++i) {
string p = c[i];
for (int j = (i + 1); j < (n); ++j) {
string q = c[j];
string r = "";
for (int m = (0); m < (k); ++m) {
if (p[m] == q[m])
r += q[m];
else
r += 'E' + 'T' + 'S' - p[m] - q[m];
}
int l = lower_bound(c.begin(), c.end(), r) - c.begin();
if (l > j && l < n && c[l] == r) ans++;
}
}
cout << ans << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, k;
cin >> n >> k;
vector<string> v(n);
map<string, long long> s;
for (long long i = 0; i < n; ++i) {
cin >> v[i];
s[v[i]] = i;
}
long long ans = 0;
for (long long i = 0; i < n; ++i) {
for (long long j = i + 1; j < n; ++j) {
vector<char> x(k);
for (long long l = 0; l < k; l++) {
if (v[i][l] == v[j][l])
x[l] = v[i][l];
else {
if (v[i][l] == 'S' && v[j][l] == 'E') x[l] = 'T';
if (v[i][l] == 'E' && v[j][l] == 'S') x[l] = 'T';
if (v[i][l] == 'S' && v[j][l] == 'T') x[l] = 'E';
if (v[i][l] == 'T' && v[j][l] == 'S') x[l] = 'E';
if (v[i][l] == 'T' && v[j][l] == 'E') x[l] = 'S';
if (v[i][l] == 'E' && v[j][l] == 'T') x[l] = 'S';
}
}
string sp(x.begin(), x.end());
if (s[sp] > j) ans++;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
long long int ans = 0;
cin >> n >> k;
unordered_map<string, int> h;
string str;
vector<string> arr;
for (int i = 0; i < n; i++) {
cin >> str;
arr.push_back(str);
h[str]++;
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
string temp;
for (int p = 0; p < k; p++) {
if (arr[i][p] == arr[j][p])
temp += arr[i][p];
else if ('T' != arr[i][p] && 'T' != arr[j][p])
temp += "T";
else if ('S' != arr[i][p] && 'S' != arr[j][p])
temp += "S";
else
temp += "E";
}
h[arr[i]]--;
h[arr[j]]--;
ans = ans + h[temp];
h[arr[i]]++;
h[arr[j]]++;
}
}
cout << ans / 3 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
string gets(string a, string b, long long k) {
string res;
for (long long i = 0; i < k; i++) {
if (a[i] == b[i]) res += a[i];
if (a[i] == 'S' && b[i] == 'E') res += 'T';
if (a[i] == 'S' && b[i] == 'T') res += 'E';
if (a[i] == 'E' && b[i] == 'S') res += 'T';
if (a[i] == 'E' && b[i] == 'T') res += 'S';
if (a[i] == 'T' && b[i] == 'E') res += 'S';
if (a[i] == 'T' && b[i] == 'S') res += 'E';
}
return res;
}
void solve() {
long long n, k, ans = 0;
cin >> n >> k;
vector<string> s(n);
for (long long i = 0; i <= n - 1; i++) cin >> s[i];
for (long long i = 0; i + 1 < n; i++) {
set<string> ok;
for (long long j = i + 1; j < n; j++) {
string a = gets(s[i], s[j], k);
if (ok.count(a))
ans++;
else
ok.insert(s[j]);
}
}
cout << ans << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
long long tc = 1;
while (tc--) solve();
}
|
#include <bits/stdc++.h>
using namespace std;
string get_st(string st1, string st2) {
string st;
long long i;
for (i = 0; i < st1.size(); i++) {
char ch = st1[i];
char ch2 = st2[i];
char res;
if (ch == ch2)
st.push_back(ch);
else {
if (ch > ch2) swap(ch, ch2);
if (ch == 'E' && ch2 == 'S') res = 'T';
if (ch == 'E' && ch2 == 'T') res = 'S';
if (ch == 'S' && ch2 == 'T') res = 'E';
st.push_back(res);
}
}
return st;
}
int main() {
long long n, m, i, j, t, ans = 0, c;
vector<string> v;
map<string, long long> mp, mp1;
string st, st1, st2;
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> st;
mp[st]++;
v.push_back(st);
}
for (i = 0; i < v.size(); i++) {
mp1 = mp;
for (j = i + 1; j < v.size(); j++) {
st1 = v[i], st2 = v[j];
st = get_st(st1, st2);
c = mp1[st];
if (st == st1) c--;
if (st == st2) c--;
ans += c;
mp1[st2]--;
}
mp[v[i]]--;
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 90;
int n, m;
string ss[maxn];
set<string> p;
int ans = 0;
int main() {
cin >> n >> m;
string s;
for (int i = 0; i < n; i++) {
cin >> ss[i];
p.insert(ss[i]);
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string str = "";
for (int k = 0; k < m; k++) {
if (ss[i][k] == ss[j][k])
str += ss[i][k];
else
str += 'S' + 'E' + 'T' - ss[i][k] - ss[j][k];
}
if (p.find(str) != p.end()) ans++;
}
}
cout << ans / 3 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1510;
int n, m;
map<string, int> mapa;
string niz[MAXN];
long long int rj = 0;
string f(string a, string b) {
string ret;
for (int i = (0); i < (m); i++) {
if (a[i] == b[i]) {
ret.push_back(a[i]);
continue;
}
char c = (char)('S' + 'E' + 'T' - a[i] - b[i]);
ret.push_back(c);
}
return ret;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = (0); i < (n); i++) cin >> niz[i];
for (int i = (0); i < (n); i++) {
for (int j = (i + 1); j < (n); j++) {
string s = f(niz[i], niz[j]);
rj += mapa[s];
}
mapa[niz[i]]++;
}
cout << rj << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXn = 3e5 + 5;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
vector<string> v(n);
map<string, int> m;
for (int i = 0; i < n; i++) {
cin >> v[i];
m[v[i]]++;
}
long long ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
string t = "";
for (int l = 0; l < k; l++) {
char a = v[i][l], b = v[j][l];
if (a == b)
t += a;
else {
if ((a == 'S' && b == 'E') || (a == 'E' && b == 'S'))
t += 'T';
else if ((a == 'S' && b == 'T') || (a == 'T' && b == 'S'))
t += 'E';
else if ((a == 'T' && b == 'E') || (a == 'E' && b == 'T'))
t += 'S';
}
}
ans += m[t];
}
}
ans /= 3;
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string s[n];
map<string, int> w;
int ans = 0;
for (int i = 0; i < int(n); i++) {
cin >> s[i];
w[s[i]]++;
}
for (int i = 0; i < int(n); i++) {
for (int j = i + 1; j < n; j++) {
string d = "";
for (int g = 0; g < int(k); g++) {
if (s[i][g] == s[j][g]) {
d += s[i][g];
} else {
if (s[i][g] != 'S' && s[j][g] != 'S') d += 'S';
if (s[i][g] != 'E' && s[j][g] != 'E') d += 'E';
if (s[i][g] != 'T' && s[j][g] != 'T') d += 'T';
}
}
if (w.count(d)) {
ans++;
}
}
}
cout << (ans / 3) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[1510][32], n, k;
char chars[3] = {'S', 'E', 'T'};
unordered_set<string> b;
string s;
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < k; j++) {
switch (s[j]) {
case 'S':
a[i][j] = 0;
break;
case 'E':
a[i][j] = 1;
break;
case 'T':
a[i][j] = 2;
break;
}
}
b.insert(s);
}
string cur;
long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
cur = "";
for (int h = 0; h < k; h++) {
cur += chars[(3 - (a[i][h] + a[j][h]) % 3) % 3];
}
if (b.find(cur) != b.end()) ans++;
}
}
cout << ans / 3 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void fun() {
int n, k;
cin >> n >> k;
map<string, int> m;
string s;
string a[n];
for (int i = 0; i < n; i++) {
cin >> s;
a[i] = s;
m[s]++;
}
int c = 0;
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) {
s = "";
for (int p = 0; p < k; p++) {
if (a[i][p] == a[j][p])
s += a[i][p];
else
s += (char)('S' + 'E' + 'T' - a[i][p] - a[j][p]);
}
c += m[s];
}
cout << c / 3 << endl;
}
int main() {
{ fun(); }
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e9 + 7;
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T> v) {
os << "(" << v.first << ", " << v.second << ")";
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << " ";
}
os << v[i];
}
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<vector<T>> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << endl;
}
os << v[i];
}
return os;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long n, k;
cin >> n >> k;
vector<string> s(n);
for (int i = 0; i < (int)n; ++i) cin >> s[i];
map<string, int> mp;
for (int i = 0; i < (int)n; ++i) mp[s[i]]++;
long long res = 0;
for (int i = 0; i < (int)n; ++i) {
for (int j = 0; j < (int)n; ++j) {
if (i > j) continue;
if (s[i] == s[j]) {
res += max(mp[s[i]] - 2, 0);
} else {
string t = "";
for (int l = 0; l < (int)k; ++l) {
if (s[i][l] == 'E' && s[j][l] == 'T') t += 'S';
if (s[i][l] == 'S' && s[j][l] == 'T') t += 'E';
if (s[i][l] == 'E' && s[j][l] == 'S') t += 'T';
if (s[i][l] == 'T' && s[j][l] == 'E') t += 'S';
if (s[i][l] == 'T' && s[j][l] == 'S') t += 'E';
if (s[i][l] == 'S' && s[j][l] == 'E') t += 'T';
if (s[i][l] == 'S' && s[j][l] == 'S') t += 'S';
if (s[i][l] == 'E' && s[j][l] == 'E') t += 'E';
if (s[i][l] == 'T' && s[j][l] == 'T') t += 'T';
}
res += mp[t];
}
}
}
cout << res / 3 << endl;
assert(res % 3 == 0);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e9 + 7;
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T> v) {
os << "(" << v.first << ", " << v.second << ")";
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << " ";
}
os << v[i];
}
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<vector<T>> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << endl;
}
os << v[i];
}
return os;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long n, k;
cin >> n >> k;
vector<string> s(n);
for (int i = 0; i < (int)n; ++i) cin >> s[i];
map<string, long long> mp;
for (int i = 0; i < (int)n; ++i) mp[s[i]]++;
long long res = 0;
for (int i = 0; i < (int)n; ++i) {
for (int j = 0; j < (int)n; ++j) {
if (i > j) continue;
if (s[i] == s[j]) {
res += max(mp[s[i]] - 2, 0ll);
} else {
string t = "";
for (int l = 0; l < (int)k; ++l) {
char x1 = s[i][l];
char x2 = s[j][l];
if (x1 == 'E' && x2 == 'T') t += 'S';
if (x1 == 'S' && x2 == 'T') t += 'E';
if (x1 == 'E' && x2 == 'S') t += 'T';
if (x1 == 'T' && x2 == 'E') t += 'S';
if (x1 == 'T' && x2 == 'S') t += 'E';
if (x1 == 'S' && x2 == 'E') t += 'T';
if (x1 == 'S' && x2 == 'S') t += 'S';
if (x1 == 'E' && x2 == 'E') t += 'E';
if (x1 == 'T' && x2 == 'T') t += 'T';
}
res += mp[t];
}
}
}
cout << res / 3 << endl;
assert(res % 3 == 0);
return 0;
}
|
#include <bits/stdc++.h>
long long n, i, j, h, k, t, d, m;
using namespace std;
char check[3] = {'S', 'E', 'T'};
string s[1505], ss;
unordered_map<string, long long> ma[1505];
char ec(char a, char b) {
for (int i = 0; i < 3; i++)
if ((a != b && check[i] != a && check[i] != b) || (a == b && b == check[i]))
return check[i];
}
int main() {
long long res = 0;
cin >> n >> k;
for (i = 1; i <= n; i++) cin >> s[i];
ss = s[1];
for (i = 1; i <= n; i++) {
ma[i][s[i + 1]]++;
for (j = i + 2; j <= n; j++) {
for (t = 0; t < k; t++) ss[t] = ec(s[i][t], s[j][t]);
res += ma[i][ss];
ma[i][s[j]]++;
}
}
cout << res << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int lin, col;
scanf("%d %d%*c", &lin, &col);
vector<string> strs;
set<string> strsSet;
string s;
for (int i = 0; i < lin; i++) {
cin >> s;
strs.push_back(s);
strsSet.insert(s);
}
int resp = 0;
set<pair<string, pair<string, string> > > sols;
for (int i = 0; i < lin; i++) {
string a = strs[i];
for (int j = i + 1; j < lin; j++) {
string b = strs[j];
string proc;
for (int k = 0; k < col; k++) {
if (a[k] == b[k]) {
proc += b[k];
} else {
if ((a[k] == 'S' && b[k] == 'E') || (a[k] == 'E' && b[k] == 'S')) {
proc += 'T';
} else if ((a[k] == 'S' && b[k] == 'T') ||
(a[k] == 'T' && b[k] == 'S')) {
proc += 'E';
} else if ((a[k] == 'E' && b[k] == 'T') ||
(a[k] == 'T' && b[k] == 'E')) {
proc += 'S';
}
}
}
if (strsSet.find(proc) != strsSet.end()) {
vector<string> v = {a, b, proc};
sort(v.begin(), v.end());
sols.insert({v[0], {v[1], v[2]}});
}
}
}
printf("%d\n", sols.size());
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int sieve_size = 15000002;
bool sieve[sieve_size + 1];
vector<long long> prime;
void Sieve() {
prime.push_back(2);
for (int i = 3; i * i <= sieve_size; i += 2) {
if (!sieve[i]) {
long long p = i * 2;
for (int j = i * i; j <= sieve_size; j += p) {
sieve[j] = true;
}
}
}
for (int i = 3; i <= sieve_size; i += 2) {
if (!sieve[i]) prime.push_back(i);
}
}
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
inline int GA(long long n, vector<long long>& vec) {
for (int i = 0; i < n; ++i) {
long long x;
cin >> x;
vec.push_back(x);
}
return 0;
}
inline int GAEG(long long m, vector<long long> vec[]) {
for (int i = 0; i < m; ++i) {
long long x, y;
cin >> x >> y;
x--, y--;
vec[x].push_back(y);
vec[y].push_back(x);
}
return 0;
}
bool isvalid(long long xx, long long yy, long long n, long long m) {
return (xx >= 0 && xx < n && yy >= 0 && yy < m);
}
long long pw(long long x, long long y, long long dr) {
if (y == 0) return 1;
long long o = y / 2;
long long f = pw(x, o, dr) % dr;
if (y % 2) {
return (((f * f) % dr) * x) % dr;
} else
return (f * f) % dr;
}
map<string, long long> mp;
map<pair<char, char>, char> qq;
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
;
long long n, m;
cin >> n >> m;
qq[make_pair('S', 'T')] = 'E';
qq[make_pair('T', 'S')] = 'E';
qq[make_pair('E', 'T')] = 'S';
qq[make_pair('T', 'E')] = 'S';
qq[make_pair('S', 'E')] = 'T';
qq[make_pair('E', 'S')] = 'T';
vector<string> ss;
for (int i = 0; i < n; ++i) {
string x;
cin >> x;
mp[x]++;
ss.push_back(x);
}
long long ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
string s = "";
for (int k = 0; k < m; ++k) {
if (ss[i][k] != ss[j][k])
s += qq[make_pair(ss[i][k], ss[j][k])];
else
s += ss[i][k];
}
if (mp[s] > 0) ans++;
}
}
cout << ans / 3 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s[1505];
int main() {
map<string, long long> M;
long long n, k;
cin >> n >> k;
for (long long i = 0; i < n; i++) {
cin >> s[i];
M[s[i]]++;
}
long long r = 0;
for (long long i = 0; i < n; i++) {
for (long long j = i + 1; j < n; j++) {
string ns = "";
for (long long x = 0; x < k; x++) {
if (s[i][x] == s[j][x]) {
ns.push_back(s[j][x]);
} else {
if ((s[i][x] == 'E' or s[i][x] == 'T') and
(s[j][x] == 'E' or s[j][x] == 'T'))
ns.push_back('S');
if ((s[i][x] == 'S' or s[i][x] == 'T') and
(s[j][x] == 'S' or s[j][x] == 'T'))
ns.push_back('E');
if ((s[i][x] == 'E' or s[i][x] == 'S') and
(s[j][x] == 'E' or s[j][x] == 'S'))
ns.push_back('T');
}
}
r = r + M[ns];
}
}
cout << r / 3;
}
|
#include <bits/stdc++.h>
using namespace std;
int d4x[4] = {1, 0, -1, 0};
int d4y[4] = {0, 1, 0, -1};
int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long oo = 1e18;
const long long maxN = 1e6;
const long long MOD = 1e9 + 7;
void maximize(int &a, int b) { a = max(a, b); }
void minimize(int &a, int b) { a = min(a, b); }
long long p[maxN];
map<string, int> cnt;
string s[maxN];
void solve() {
long long ans = 0;
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> s[i];
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
string need = "";
for (int c = 0; c < k; c++) {
if (s[i][c] == s[j][c])
need += s[i][c];
else {
if (s[i][c] != 'S' && s[j][c] != 'S') need += 'S';
if (s[i][c] != 'E' && s[j][c] != 'E') need += 'E';
if (s[i][c] != 'T' && s[j][c] != 'T') need += 'T';
}
}
if (cnt.count(need)) ans += cnt[need];
}
cnt[s[i]]++;
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1505;
string s[N];
map<string, int> cnt;
int n, k;
void work() {
long long ret = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string cur = "";
for (int kk = 0; kk < k; kk++) {
if (s[i][kk] == s[j][kk]) {
cur += s[i][kk];
} else {
if ('S' != s[i][kk] && 'S' != s[j][kk]) {
cur += 'S';
}
if ('E' != s[i][kk] && 'E' != s[j][kk]) {
cur += 'E';
}
if ('T' != s[i][kk] && 'T' != s[j][kk]) {
cur += 'T';
}
}
}
if (cnt.count(cur)) {
ret += cnt[cur];
}
}
cnt[s[i]]++;
}
cout << ret << endl;
}
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
work();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T = 1;
while (T--) {
int n, x;
cin >> n >> x;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
int ans = 0;
sort(s.begin(), s.end());
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string temp;
for (int k = 0; k < x; k++) {
if (s[i][k] == s[j][k]) {
temp.push_back(s[i][k]);
} else {
if ((s[i][k] == 'S' && s[j][k] == 'E') ||
(s[j][k] == 'S' && s[i][k] == 'E')) {
temp.push_back('T');
} else if ((s[i][k] == 'S' && s[j][k] == 'T') ||
(s[j][k] == 'S' && s[i][k] == 'T')) {
temp.push_back('E');
} else {
temp.push_back('S');
}
}
}
if (binary_search(s.begin() + j, s.end(), temp)) {
ans++;
}
}
}
cout << ans;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool checkset(vector<string>& card, int i, int j, int k) {
int sz = card[i].size();
for (int pos = 0; pos < sz; ++pos) {
if (card[i][pos] == card[j][pos] && card[j][pos] == card[k][pos]) continue;
if (card[i][pos] == card[j][pos] || card[j][pos] == card[k][pos] ||
card[k][pos] == card[i][pos])
return false;
}
return true;
}
int main() {
int n, sz;
cin >> n >> sz;
vector<string> card(n);
unordered_map<string, int> m;
unordered_map<string, char> toFind;
int cnt = 0;
for (int i = 0; i < n; ++i) {
cin >> card[i];
m[card[i]] = i;
}
toFind["ST"] = 'E';
toFind["TS"] = 'E';
toFind["ET"] = 'S';
toFind["TE"] = 'S';
toFind["SE"] = 'T';
toFind["ES"] = 'T';
for (int i = 0; i < n - 2; ++i) {
for (int j = i + 1; j < n - 1; ++j) {
string matched;
for (int k = 0; k < sz; ++k) {
if (card[i][k] == card[j][k]) matched.push_back(card[i][k]);
if (card[i][k] != card[j][k]) {
string tmp = "";
tmp += card[i][k];
tmp += card[j][k];
matched.push_back(toFind[tmp]);
}
}
if (m.find(matched) != m.end()) {
if (m[matched] > j) ++cnt;
}
}
}
cout << cnt << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
string s[n];
set<string> store;
for (int i = 0; i < n; i++) {
cin >> s[i];
store.insert(s[i]);
}
int cnt = 0;
for (int i = 0; i < n; i++) {
set<string> v;
store.erase(s[i]);
for (int j = i + 1; j < n; j++) {
v.insert(s[j]);
store.erase(s[j]);
string temp;
for (int l = 0; l < k; l++) {
if (s[i][l] == s[j][l]) {
temp += s[i][l];
} else {
temp += ('S' + 'E' + 'T' - s[i][l] - s[j][l]);
}
}
if (store.find(temp) != store.end()) {
cnt++;
v.insert(temp);
store.erase(temp);
}
}
for (auto it : v) {
store.insert(it);
}
}
cout << cnt << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, r, k, c, m[1500][1500];
string a[1500];
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int t = 0; t < n; t++) {
if (i == t) continue;
c = 0;
for (int e = 0; e < k; e++) {
if (a[i][e] == a[t][e]) c += 1 << e;
}
m[i][t] = c;
}
}
for (int i = 0; i < n; i++) {
for (int t = i + 1; t < n; t++) {
for (int e = t + 1; e < n; e++) {
if (m[i][t] == m[i][e] && m[i][t] == m[t][e]) r++;
}
}
}
cout << r;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1505;
string arr[mxn];
int n, k;
void solve() {
if (n < 3) {
cout << 0 << '\n';
return;
}
long long freq = 0;
map<string, int> m;
for (int i = 1; i < n; i++) {
m[arr[i]]++;
}
for (int i = 1; i < n; i++) {
m[arr[i]]--;
for (int j = i - 1; j >= 0; j--) {
string to_find = "";
for (int h = 0; h < k; h++) {
char f = arr[i][h];
char v = arr[j][h];
if (f == v) {
to_find += f;
} else {
if (f != 'S' && v != 'S') {
to_find += 'S';
} else if (f != 'T' && v != 'T') {
to_find += 'T';
} else if (f != 'E' && v != 'E') {
to_find += 'E';
}
}
}
freq += (long long)m[to_find];
}
}
cout << freq << '\n';
}
void read() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
while (T--) read(), solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int ESP = 1e18;
long long int INF = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long int n, k;
cin >> n >> k;
string str[n];
map<string, long long int> mp;
for (long long int i = 0; i < n; i++) {
cin >> str[i];
mp[str[i]]++;
}
long long int ans = 0;
for (long long int i = 0; i < n - 1; i++) {
for (long long int j = i + 1; j < n; j++) {
string s = "";
for (long long int p = 0; p < k; p++) {
if (str[i][p] == str[j][p])
s += str[i][p];
else
s += ((char)('S' + 'E' + 'T' - str[i][p] - str[j][p]));
}
if (mp[s]) ans++;
}
}
cout << ans / 3 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s[1505];
long long a[1505];
int K;
int check(char ss) {
if (ss == 'E') return 0;
if (ss == 'S') return 1;
if (ss == 'T') return 2;
}
char fuck(char c1, char c2) {
int ans;
ans = 'E' + 'S' + 'T' - c1 - c2;
return (char)ans;
}
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n >> K;
for (int i = 1; i <= n; i++) {
cin >> s[i];
}
sort(s + 1, s + n + 1);
for (int i = 1; i <= n; i++)
for (int k = 0; k < K; k++) {
a[i] = a[i] * 3LL + check(s[i][k]);
}
sort(a + 1, a + n + 1);
int cnt = 0, ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
char ss[35];
for (int k = 0; k < K; k++) {
if (s[i][k] == s[j][k])
ss[k] = s[i][k];
else {
ss[k] = fuck(s[i][k], s[j][k]);
}
}
long long x = 0;
for (int k = 0; k < K; k++) {
x = x * 3LL + check(ss[k]);
}
if (j == n) continue;
int y = lower_bound(a + j + 1, a + n + 1, x) - a;
if (a[n] == x) y = n;
if (x == a[y]) ans++;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::cout;
using std::pair;
using std::string;
using std::vector;
using ll = long long;
const int INF = 1e9 + 1;
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, k;
cin >> n >> k;
std::set<vector<int>> s;
vector<vector<int>> s1(n);
for (int i = 0; i < n; ++i) {
vector<int> v(k);
for (int &j : v) {
char c;
cin >> c;
if (c == 'S') j = 0;
if (c == 'E') j = 1;
if (c == 'T') j = 2;
}
s.insert(v);
s1[i] = v;
}
int ans = 0;
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j) {
vector<int> v(k);
for (int t = 0; t < k; ++t)
if (s1[i][t] == s1[j][t])
v[t] = s1[i][t];
else
v[t] = 3 - s1[i][t] - s1[j][t];
if (s.find(v) != s.end()) ++ans;
}
cout << ans / 3;
return 0;
}
|
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
constexpr int Dir4[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
constexpr int Dir8[8][2] = {{-1, -1}, {-1, 1}, {0, -1},
{0, 1}, {1, -1}, {1, 1}};
constexpr double EPS = 1e-8;
const double PI = acos(-1);
using int16 = short;
using uint16 = unsigned short;
using uint = unsigned int;
using int64 = long long;
using uint64 = unsigned long long;
using pii = pair<int, int>;
auto Equal = [](double a, double b) { return fabs(a - b) < EPS; };
constexpr int MAXN = 1500;
int n, k;
string s[MAXN + 1];
unordered_map<string, int64> UM;
unordered_map<char, int> convert;
int main() {
convert['S'] = 1;
convert['E'] = 2;
convert['T'] = 4;
convert[1] = 'S';
convert[2] = 'E';
convert[4] = 'T';
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int64 ans = 0;
cin >> n >> k;
for (int i = (0); i < (n); ++i) {
cin >> s[i];
++UM[s[i]];
}
for (int i = (0); i < (n); ++i) {
for (int j = (i + 1); j < (n); ++j) {
string tmp = "";
for (int k = (0); k < (s[i].size()); ++k)
if (s[i][k] == s[j][k])
tmp += s[i][k];
else {
int x = convert[s[i][k]] | convert[s[j][k]];
tmp += convert[(~x) & 7];
}
ans += UM[tmp];
}
}
cout << ans / 3;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string st2;
cin >> st2;
unordered_set<string> se;
se.insert(st2);
int ct = 0;
for (int jk = 1; jk < n; jk++) {
string st;
cin >> st;
for (auto x : se) {
for (int i = 0; i < k; i++) {
if (st[i] != x[i]) x[i] = 236 - st[i] - x[i];
}
if (se.find(x) != se.end()) ct++;
}
se.insert(st);
}
cout << ct / 2;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
string str[n];
unordered_map<string, int> table;
unordered_map<string, string> sub{{"SE", "T"}, {"ES", "T"}, {"ST", "E"},
{"TS", "E"}, {"TE", "S"}, {"ET", "S"}};
for (int i = 0; i < n; i++) {
cin >> str[i];
table[str[i]] = 1;
}
long long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string tmp = "";
for (int z = 0; z < k; z++) {
if (str[i][z] == str[j][z]) {
tmp += str[i][z];
} else {
string comb = "";
comb += str[i][z];
comb += str[j][z];
tmp += sub[comb];
}
}
if (table.find(tmp) != table.end()) {
ans++;
}
}
}
cout << ans / 3 << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<string, long long>& a, pair<string, long long>& b) {
return a.second < b.second;
}
long long gcd(long long a, long long b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
int32_t main() {
long long n, k;
cin >> n >> k;
vector<string> s(n);
map<string, long long> cnt;
for (long long i = 0; i < n; i++) {
cin >> s[i];
cnt[s[i]]++;
}
long long ans = 0;
for (long long i = 0; i < n; i++) {
for (long long j = i + 1; j < n; j++) {
string need;
for (long long c = 0; c < k; c++) {
if (s[i][c] == s[j][c]) {
need += s[i][c];
} else if ((s[i][c] == 'S' && s[j][c] == 'E') ||
(s[i][c] == 'E' && s[j][c] == 'S')) {
need += 'T';
} else if ((s[i][c] == 'S' && s[j][c] == 'T') ||
(s[i][c] == 'T' && s[j][c] == 'S')) {
need += 'E';
} else if ((s[i][c] == 'T' && s[j][c] == 'E') ||
(s[i][c] == 'E' && s[j][c] == 'T')) {
need += 'S';
}
}
if (cnt[need] > 0) {
ans += cnt[need];
}
}
}
cout << ans / 3;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int pow1(long long int n, long long int p) {
if (p == 0) return 1;
long long int x = pow1(n, p / 2);
x = (x * x) % 1000000007;
if (p % 2 == 0)
return x;
else
return (x * n) % 1000000007;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int n, k;
cin >> n >> k;
vector<string> v;
map<string, long long int> m;
for (long long int i = 0; i < n; i++) {
string s1;
cin >> s1;
m[s1]++;
v.push_back(s1);
}
long long int c2 = 0;
for (long long int i = 0; i < (long long int)v.size(); i++) {
string s1 = v[i];
for (long long int j = i + 1; j < (long long int)v.size(); j++) {
string s2 = v[j];
string s3 = "";
for (long long int i = 0; i < k; i++) {
if (s1[i] == s2[i]) {
s3 += s1[i];
} else {
char c = ' ';
if (s1[i] == 'S') {
if (s2[i] == 'T') {
c = 'E';
} else {
c = 'T';
}
} else if (s1[i] == 'T') {
if (s2[i] == 'E') {
c = 'S';
} else {
c = 'E';
}
} else if (s1[i] == 'E') {
if (s2[i] == 'S') {
c = 'T';
} else {
c = 'S';
}
}
s3 += c;
}
}
if (m[s3] != 0) c2++;
}
}
c2 /= 3;
cout << c2 << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, K, i, j, k, ct = 0;
cin >> n >> K;
set<string> S;
string s;
vector<string> V;
for (i = 0; i < n; i++) {
cin >> s;
V.push_back(s);
S.insert(s);
}
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
string s1 = "";
for (k = 0; k < K; k++) {
if (V[i][k] == V[j][k]) {
s1.push_back(V[i][k]);
} else {
if (V[i][k] == 'S' && V[j][k] == 'T')
s1.push_back('E');
else if (V[i][k] == 'S' && V[j][k] == 'E')
s1.push_back('T');
else if (V[i][k] == 'T' && V[j][k] == 'S')
s1.push_back('E');
else if (V[i][k] == 'E' && V[j][k] == 'S')
s1.push_back('T');
else
s1.push_back('S');
}
}
if (S.find(s1) != S.end()) ct++;
}
}
cout << ct / 3 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
string str[100001];
map<string, long long int> m;
int main() {
ios::sync_with_stdio(false);
;
cin.tie(0);
;
long long int i, j, n, k, x, y, l, ans = 0;
string temp;
cin >> n >> k;
for (i = 1; i <= n; i++) cin >> str[i];
for (i = 1; i <= n; i++) {
m.clear();
for (j = i + 1; j <= n; j++) m[str[j]]++;
for (j = i + 1; j <= n; j++) {
m[str[j]]--;
temp = "";
for (l = 0; l < k; l++) {
if (str[i][l] == str[j][l])
temp += str[i][l];
else {
if (str[i][l] != 'S' && str[j][l] != 'S')
temp += 'S';
else if (str[i][l] != 'E' && str[j][l] != 'E')
temp += 'E';
else if (str[i][l] != 'T' && str[j][l] != 'T')
temp += 'T';
}
}
ans += m[temp];
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
string s;
set<string> card_bank;
std::vector<string> cards;
std::map<int, char> diff_feat;
diff_feat['S' + 'T'] = 'E';
diff_feat['S' + 'E'] = 'T';
diff_feat['E' + 'T'] = 'S';
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> s;
cards.push_back(s);
card_bank.insert(s);
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string aux_card = "";
for (int feat = 0; feat < k; feat++) {
if (cards[i][feat] == cards[j][feat])
aux_card += cards[i][feat];
else
aux_card += diff_feat[cards[i][feat] + cards[j][feat]];
}
if (card_bank.find(aux_card) != card_bank.end()) ans++;
}
}
printf("%d\n", ans / 3);
}
|
#include <bits/stdc++.h>
using namespace std;
int IT_MAX = 1 << 17;
int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x0f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
long long mod(long long a, long long m) {
return (a + (abs(a) / m) * m + m) % m;
}
string get_s(string &l, string &r) {
string ans;
for (int i = 0; i < l.size(); ++i) {
if (l[i] == r[i]) {
ans.push_back(l[i]);
} else {
if (l[i] != 'S' && r[i] != 'S') {
ans.push_back('S');
}
if (l[i] != 'E' && r[i] != 'E') {
ans.push_back('E');
}
if (l[i] != 'T' && r[i] != 'T') {
ans.push_back('T');
}
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
long long n, k;
cin >> n >> k;
vector<string> v(n);
set<string> s;
for (int i = 0; i < n; ++i) {
cin >> v[i];
s.insert(v[i]);
}
long long cnt = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (s.count(get_s(v[i], v[j]))) ++cnt;
}
}
cout << cnt / 3;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<string> str(1500);
map<string, int> mp;
map<string, int>::iterator it;
string word;
void call(string ff, string ss, long long sz) {
for (long long i = 0; i < sz; i++) {
if (ff[i] == ss[i])
word += ff[i];
else
word += 'S' + 'E' + 'T' - ff[i] - ss[i];
}
}
int main() {
long long n, i, j, k, cnt;
cin >> n >> k;
for (i = 0; i < n; i++) {
cin >> str[i];
mp.insert({str[i], 0});
}
for (i = 0, cnt = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (i != j) {
call(str[i], str[j], k);
it = mp.find(word);
if (it != mp.end()) cnt++;
word.clear();
}
}
}
cout << cnt / 3 << endl;
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long INF = 4e18;
const int inf = 1e9;
const int N = 2e5 + 5;
const long long mod = 998244353;
char uni(char a, char b) {
for (char i : {'S', 'E', 'T'}) {
if (i != a && i != b) {
return i;
}
}
}
int make_h(string s) {
long long h = 0, p = 31, q = 1;
for (int i = 0; i < s.size(); i++) {
h += (s[i] - 'A' + 1) * q;
q *= p;
}
return h;
}
void solve() {
int n, k;
cin >> n >> k;
string s[n];
map<long long, int> mp;
long long h[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
mp[make_h(s[i])]++;
h[i] = make_h(s[i]);
}
long long ans = 0;
for (int i = 0; i < n - 1; i++) {
mp[h[i]]--;
for (int j = i + 1; j < n; j++) {
string x = s[i];
for (int p = 0; p < k; p++) {
if (s[i][p] != s[j][p]) {
x[p] = uni(s[i][p], s[j][p]);
} else {
x[p] = s[i][p];
}
}
mp[h[j]]--;
ans += mp[make_h(x)];
mp[h[j]]++;
}
}
cout << ans / 2 << '\n';
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
string a[n];
char arr[100][100];
arr[83][83] = 'S';
arr[69][69] = 'E';
arr[84][84] = 'T';
arr[83][69] = 'T';
arr[69][83] = 'T';
arr[69][84] = 'S';
arr[84][69] = 'S';
arr[83][84] = 'E';
arr[84][83] = 'E';
unordered_map<string, int> h;
long long int cnt = 0;
char third[k + 1];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
h[a[i]] = i;
}
for (long long int i = 0; i < n - 1; i++) {
for (long long int j = i + 1; j < n; j++) {
for (long long int m = 0; m < k; m++) {
third[m] = arr[a[i][m] - '0' + 48][a[j][m] - '0' + 48];
}
third[k] = '\0';
if (h.count(third) != 0) {
if (h[third] > j) cnt++;
}
}
}
cout << cnt << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int tc;
void solve() {
map<string, int> mp;
vector<string> v;
string s;
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> s;
mp[s]++;
if (mp[s] == 1) v.push_back(s);
}
int ans = 0;
set<vector<string> > st;
for (int i = 0; i < v.size(); i++) {
vector<string> vv;
if (mp[v[i]] >= 3) {
vv.push_back(v[i]);
vv.push_back(v[i]);
vv.push_back(v[i]);
st.insert(vv);
}
for (int j = i + 1; j < v.size(); j++) {
string ss;
for (int p = 0; p < k; p++) {
if (v[i][p] == v[j][p])
ss.push_back(v[i][p]);
else if (v[i][p] != 'S' && v[j][p] != 'S')
ss.push_back('S');
else if (v[i][p] != 'E' && v[j][p] != 'E')
ss.push_back('E');
else
ss.push_back('T');
}
if (mp[ss]) {
vv.clear();
vv.push_back(v[i]);
vv.push_back(v[j]);
vv.push_back(ss);
sort(vv.begin(), vv.end());
st.insert(vv);
}
}
}
cout << st.size() << "\n";
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
vector<string> al(n);
set<string> a;
for (int i = 0; i < n; i++) {
cin >> al[i];
a.insert(al[i]);
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string s3 = "";
for (int m = 0; m < k; m++) {
if (al[i][m] == 'S' && al[j][m] == 'T') {
s3 += 'E';
}
if (al[i][m] == 'S' && al[j][m] == 'S') {
s3 += 'S';
}
if (al[i][m] == 'S' && al[j][m] == 'E') {
s3 += 'T';
}
if (al[i][m] == 'E' && al[j][m] == 'E') {
s3 += 'E';
}
if (al[i][m] == 'E' && al[j][m] == 'T') {
s3 += 'S';
}
if (al[i][m] == 'E' && al[j][m] == 'S') {
s3 += 'T';
}
if (al[i][m] == 'T' && al[j][m] == 'T') {
s3 += 'T';
}
if (al[i][m] == 'T' && al[j][m] == 'S') {
s3 += 'E';
}
if (al[i][m] == 'T' && al[j][m] == 'E') {
s3 += 'S';
}
}
if (a.find(s3) != a.end()) {
ans++;
}
}
}
cout << ans / 3;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
map<string, int> mp;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
mp.insert({s[i], i});
}
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string to_be = "";
for (int l = 0; l < k; l++) {
if (s[i][l] == s[j][l]) {
to_be += s[i][l];
} else {
if (s[i][l] == 'S' && s[j][l] == 'E') {
to_be += "T";
} else if (s[i][l] == 'E' && s[j][l] == 'S') {
to_be += "T";
} else if (s[i][l] == 'S' && s[j][l] == 'T') {
to_be += "E";
} else if (s[i][l] == 'T' && s[j][l] == 'S') {
to_be += "E";
} else if (s[i][l] == 'T' && s[j][l] == 'E') {
to_be += "S";
} else if (s[i][l] == 'E' && s[j][l] == 'T') {
to_be += "S";
}
}
}
cnt += mp.count(to_be);
}
}
cout << cnt / 3 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
auto clk = clock();
void solve() {
long long n, k;
cin >> n >> k;
string s[n];
map<string, long long> c;
for (long long i = 0; i < n; i++) cin >> s[i];
for (long long i = 0; i < n; i++) c[s[i]]++;
long long ans = 0;
for (long long i = 0; i < n; i++) {
for (long long j = i + 1; j < n; j++) {
string t = "";
for (long long o = 0; o < k; o++) {
if (s[i][o] == s[j][o])
t += s[i][o];
else
t += ('S' + 'E' + 'T' - s[i][o] - s[j][o]);
}
if (c[t] > 0) ans++;
}
}
cout << ans / 3 << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout << fixed << setprecision(8);
long long t = 1;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, k;
cin >> n >> k;
string s[n + 1];
set<string> ar;
for (int x = 0; x < n; x++) {
cin >> s[x];
ar.insert(s[x]);
}
char a[3] = {'S', 'E', 'T'};
long long int ans = 0;
for (int x = 0; x < n; x++) {
for (int y = x + 1; y < n; y++) {
string d;
for (int z = 0; z < k; z++) {
if (s[x][z] == s[y][z]) {
d += s[x][z];
} else {
for (int i = 0; i < 3; i++) {
if (a[i] != s[x][z] && a[i] != s[y][z]) {
d += a[i];
break;
}
}
}
}
if (d.length() != 0)
if (ar.count(d)) ++ans;
}
}
cout << ans / 3 << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
void printi(vector<int> &l) {
for (long long i = 0; i < l.size(); ++i) {
cout << l[i] << " ";
}
cout << endl;
}
void printl(vector<long long> &l) {
for (long long i = 0; i < l.size(); ++i) {
cout << l[i] << " ";
}
cout << endl;
}
template <class T>
istream &operator>>(istream &in, vector<T> &arr) {
for (T &i : arr) {
in >> i;
}
return in;
}
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
unordered_map<string, long long> s;
long long n, k;
cin >> n >> k;
vector<string> str;
for (int i = 0; i < n; ++i) {
string f;
cin >> f;
if (s.count(f) == 0) {
s[f] = 0;
str.push_back(f);
}
s[f] += 1;
}
long long ans = 0;
for (int i = 0; i < str.size(); ++i) {
for (int j = i + 1; j < str.size(); ++j) {
string h = "";
for (int p = 0; p < k; ++p) {
if (str[i][p] == str[j][p]) {
h.push_back(str[i][p]);
} else {
char uk = 'S' + 'E' + 'T';
uk -= str[i][p];
uk -= str[j][p];
h.push_back(uk);
}
}
if (s.count(h) == 0) s[h] = 0;
ans += s[h];
}
}
long long anss = ans / 3;
for (auto o : s) {
anss += (o.second * (o.second - 1) * (o.second - 2)) / 6;
}
cout << anss << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
solve();
return 0;
}
void solve() {
int n, k;
cin >> n >> k;
vector<string> v(n);
set<string> st;
for (auto &i : v) {
cin >> i;
st.insert(i);
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string s = v[i];
for (int q = 0; q < k; q++) {
if (v[i][q] == v[j][q]) {
s[q] = v[i][q];
} else {
if (v[i][q] == 'S') {
if (v[j][q] == 'E') {
s[q] = 'T';
} else {
s[q] = 'E';
}
} else if (v[i][q] == 'E') {
if (v[j][q] == 'S') {
s[q] = 'T';
} else {
s[q] = 'S';
}
} else {
if (v[j][q] == 'S') {
s[q] = 'E';
} else {
s[q] = 'S';
}
}
}
}
if (st.find(s) != st.end()) {
ans++;
}
}
}
cout << ans / 3;
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int n, k;
string find_third(const string a, const string b) {
string s(k, 0);
for (int i = 0; i < k; i++) {
if (a[i] == b[i])
s[i] = a[i];
else {
for (auto c : "SET") {
if (c != a[i] and c != b[i]) {
s[i] = c;
break;
}
}
}
}
return s;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(17);
cin >> n >> k;
vector<string> a(n);
unordered_map<string, int> dict;
for (int i = 0; i < n; i++) {
cin >> a[i];
dict[a[i]]++;
}
long long ans = 0;
for (int j = 0; j < n; j++) {
dict[a[j]]--;
for (int i = 0; i < j; i++) {
auto s = find_third(a[i], a[j]);
if (dict.count(s)) ans += dict[s];
}
}
cout << ans << endl;
;
return 0;
}
|
#include <bits/stdc++.h>
int cmp(int a[], int b[], int k) {
for (int l = 0; l < k; l++) {
if (a[l] < b[l]) return -1;
if (a[l] > b[l]) return 1;
}
return 0;
}
int main() {
int n, k;
int counter = 0;
scanf("%d %d", &n, &k);
int a[n][k];
for (int i = 0; i < n; i++) {
char str[30];
scanf("%s", str);
for (int j = 0; j < k; j++) {
if (str[j] == 'S') a[i][j] = 0;
if (str[j] == 'E') a[i][j] = 1;
if (str[j] == 'T') a[i][j] = 2;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - 1 - i; j++) {
if (cmp(a[j], a[j + 1], k) == 1) {
int hold[k];
for (int l = 0; l < k; l++) {
hold[l] = a[j][l];
a[j][l] = a[j + 1][l];
a[j + 1][l] = hold[l];
}
}
}
}
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++) {
int nu[k];
for (int h = 0; h < k; h++) {
if (a[i][h] + a[j][h] == 0) nu[h] = 0;
if (a[i][h] + a[j][h] == 1) nu[h] = 2;
if (a[i][h] + a[j][h] == 2) nu[h] = 1;
if (a[i][h] + a[j][h] == 3) nu[h] = 0;
if (a[i][h] + a[j][h] == 4) nu[h] = 2;
}
int flag = 0;
int b = 0;
int e = n;
while (b < e) {
if (cmp(nu, a[(b + e) / 2], k) == 0) {
flag = 1;
break;
}
if (cmp(nu, a[(b + e) / 2], k) == 1) b = (e + b) / 2;
if (cmp(nu, a[(b + e) / 2], k) == -1) e = (e + b) / 2;
if (b == e - 1) {
if (cmp(nu, a[(b + e) / 2], k) == 0) {
flag = 1;
break;
}
break;
}
}
if (flag == 1) counter++;
}
printf("%d", counter / 3);
}
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int powm(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
string trim(const string& str) {
size_t first = str.find_first_not_of(' ');
if (string::npos == first) {
return str;
}
int last = str.find_last_not_of(' ');
return str.substr(first, (last - first + 1));
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout.precision(15);
int n, q;
cin >> n >> q;
vector<string> arr(n);
map<string, bool> m;
for (int i = 0; i < n; i++) {
cin >> arr[i];
m[arr[i]] = true;
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int k = i + 1; k < n; k++) {
string str = "";
for (int p = 0; p < q; p++) {
if (arr[i][p] == arr[k][p]) {
str += arr[i][p];
} else {
char ch = 'S' + 'E' + 'T' - arr[i][p] - arr[k][p];
str += ch;
}
}
if (m.count(str)) {
ans++;
}
}
}
cout << ans / 3 << '\n';
cerr << "Time elapsed" << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
long long int f;
cin >> n >> f;
string a[n];
map<string, long long int> mp;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
}
long long int c = 0;
long long int fl = 0;
long long int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string st;
for (int k = 0; k < f; k++) {
if (a[i][k] == 'S' && a[j][k] == 'T') {
st += 'E';
}
if (a[i][k] == 'S' && a[j][k] == 'E') {
st += 'T';
}
if (a[i][k] == 'S' && a[j][k] == 'S') {
st += 'S';
}
if (a[i][k] == 'T' && a[j][k] == 'S') {
st += 'E';
}
if (a[i][k] == 'T' && a[j][k] == 'E') {
st += 'S';
}
if (a[i][k] == 'T' && a[j][k] == 'T') {
st += 'T';
}
if (a[i][k] == 'E' && a[j][k] == 'T') {
st += 'S';
}
if (a[i][k] == 'E' && a[j][k] == 'S') {
st += 'T';
}
if (a[i][k] == 'E' && a[j][k] == 'E') {
st += 'E';
}
}
ans += mp[st];
}
}
cout << ans / 3 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
string nc2i(char c1, char c2) {
if (c1 == 'S') {
if (c2 == 'E')
return "T";
else
return "E";
} else if (c1 == 'E') {
if (c2 == 'S')
return "T";
else
return "S";
} else if (c1 == 'T') {
if (c2 == 'E')
return "S";
else
return "E";
} else
assert(false);
}
void solve() {
int n;
cin >> n;
;
int k;
cin >> k;
;
vector<string> s(n);
vector<vector<int> > f(k, vector<int>(3));
for (int i = 0; i < n; i++) {
cin >> s[i];
}
sort(s.begin(), s.end());
long long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n - 1; j++) {
string se;
for (int l = 0; l < k; l++) {
if (s[i][l] == s[j][l])
se += s[i][l];
else
se += nc2i(s[i][l], s[j][l]);
}
if (binary_search(s.begin() + j + 1, s.end(), se)) {
ans++;
}
}
}
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long cnt = 0;
map<string, bool> bio;
char third(char c1, char c2) {
int s = 0, e = 0, t = 0;
if (c1 == 'S' || c2 == 'S') s++;
if (c1 == 'E' || c2 == 'E') e++;
if (c1 == 'T' || c2 == 'T') t++;
if (s == 0) return 'S';
if (e == 0) return 'E';
return 'T';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
string s[1510];
for (int i = 0; i < n; i++) {
cin >> s[i];
bio[s[i]] = true;
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (j == i) continue;
string st = s[0];
vector<int> vec;
for (int g = 0; g < k; g++) {
if (s[i][g] == s[j][g])
st[g] = s[i][g];
else
st[g] = third(s[i][g], s[j][g]);
}
if (bio[st]) cnt++;
}
}
cout << cnt / 3;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void solve() {
int n, k;
cin >> n >> k;
map<vector<int>, int> M;
int arr[n][k];
for (int i = 0; i < n; i++) {
string s;
cin >> s;
vector<int> v;
for (int j = 0; j < k; j++) {
if (s[j] == 'S') arr[i][j] = 0;
if (s[j] == 'E') arr[i][j] = 1;
if (s[j] == 'T') arr[i][j] = 2;
v.push_back(arr[i][j]);
}
M[v]++;
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
vector<int> v;
if (i == j) continue;
for (int m = 0; m < k; m++) {
if (arr[i][m] == arr[j][m]) {
v.push_back(arr[i][m]);
} else {
if (arr[i][m] == 0 && arr[j][m] == 1 ||
arr[i][m] == 1 && arr[j][m] == 0)
v.push_back(2);
if (arr[i][m] == 0 && arr[j][m] == 2 ||
arr[i][m] == 2 && arr[j][m] == 0)
v.push_back(1);
if (arr[i][m] == 2 && arr[j][m] == 1 ||
arr[i][m] == 1 && arr[j][m] == 2)
v.push_back(0);
}
}
ans += M[v];
}
}
cout << ans / 3 << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tests = 1;
while (tests--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
map<string, long long> M;
int main() {
int n, k;
cin >> n >> k;
vector<string> v;
for (int i = 0; i < n; i++) {
string x;
cin >> x;
v.push_back(x);
}
long long c = 0;
for (int i = 0; i < v.size(); i++) {
for (int j = i + 1; j < v.size(); j++) {
string ans = "";
for (int m = 0; m < k; m++) {
if (v[i][m] == v[j][m])
ans += v[i][m];
else {
if (v[i][m] == 'S' && v[j][m] == 'T' ||
v[i][m] == 'T' && v[j][m] == 'S')
ans += 'E';
else if (v[i][m] == 'E' && v[j][m] == 'T' ||
v[i][m] == 'T' && v[j][m] == 'E')
ans += 'S';
else
ans += 'T';
}
}
c += M[ans];
}
M[v[i]]++;
}
cout << c;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
unordered_map<string, int> cnt;
int n, sz;
cin >> n >> sz;
cnt.reserve(n + 10);
vector<string> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
cnt[arr[i]]++;
}
sort(arr.begin(), arr.end());
long long ans = 0;
for (int i = 0; i < n; i++) {
auto gg = cnt;
for (int j = 0; j <= i; j++) {
gg[arr[j]]--;
}
for (int j = i + 1; j < n; j++) {
gg[arr[j]]--;
string tmp = "";
for (int k = 0; k < sz; k++) {
if (arr[i][k] == arr[j][k])
tmp.push_back(arr[i][k]);
else {
string hh;
hh.push_back(arr[i][k]);
hh.push_back(arr[j][k]);
if (hh == "ST" or hh == "TS")
tmp += "E";
else if (hh == "ES" or hh == "SE")
tmp += "T";
else
tmp += "S";
}
}
ans += gg[tmp];
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t, n, m, k, q, x, a, b, c, d, w;
cin >> n >> k;
vector<string> v(n);
unordered_map<string, int> map;
for (int i = 0; i < n; i++) {
cin >> v[i];
map[v[i]] = i;
}
long long int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string s;
for (int p = 0; p < k; p++) {
if (v[i][p] == v[j][p]) {
s += v[i][p];
} else {
if (v[i][p] != 'E' && v[j][p] != 'E') {
s += 'E';
} else if (v[i][p] != 'S' && v[j][p] != 'S') {
s += 'S';
} else
s += 'T';
}
}
if (map[s] > j) {
ans++;
}
}
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long M = 1e9 + 7;
long long MOD = 998244353;
bitset<N> bs;
set<int> s[2001];
long long power(long long a, long long b) {
long long res = 1;
if (a == 0) return 0;
if (a == 1) return 1;
for (; b > 0; b >>= 1) {
if (b & 1) {
res = (res * a);
if (res > M) res %= M;
}
a = (a * a);
if (a > M) a = a % M;
}
return res;
}
int main() {
int n, k;
cin >> n >> k;
string s[n];
set<string> m;
for (int i = 0; i < n; i++) {
cin >> s[i];
m.insert(s[i]);
}
long long cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string form = "";
for (int t = 0; t < k; t++) {
if (s[i][t] == s[j][t])
form += s[i][t];
else
form += char('S' + 'E' + 'T' - s[i][t] - s[j][t]);
}
if (m.find(form) != m.end()) cnt++;
}
}
cout << cnt / 3;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
while (t--) {
int n, k;
cin >> n >> k;
string str[n];
for (int i = 0; i < n; ++i) {
cin >> str[i];
}
int ans = 0;
map<string, int> mp;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; j++) {
string temp = "";
for (int m = 0; m < k; m++) {
char c1 = str[i][m];
char c2 = str[j][m];
if ((str[i][m] == 'S' && str[j][m] == 'E') ||
str[i][m] == 'E' && str[j][m] == 'S') {
temp.push_back('T');
} else if ((c1 == 'S' && c2 == 'T') || (c1 == 'T' && c2 == 'S')) {
temp.push_back('E');
} else if ((c1 == 'T' && c2 == 'E') || (c1 == 'E' && c2 == 'T')) {
temp.push_back('S');
} else
temp.push_back(c1);
}
ans += mp[temp];
}
mp[str[i]]++;
}
cout << ans << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i;
cin >> n >> k;
vector<string> s(n);
for (i = 0; i < n; i++) {
cin >> s[i];
}
map<string, int> m;
for (i = 0; i < n; i++) {
m[s[i]] = 1;
}
int ans = 0;
for (i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string str = "";
for (int len = 0; len < k; len++) {
if (s[i][len] == s[j][len]) {
str.push_back(s[i][len]);
} else {
str.push_back('S' + 'T' + 'E' - s[i][len] - s[j][len]);
}
}
if (m[str] == 1) {
ans++;
}
}
}
cout << ans / 3 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i2 = pair<int, int>;
using vi = vector<int>;
const int N = 1509;
string A[N], B[N * N];
string third(string a, string b) {
int n = a.length();
string res = "";
for (int i = 0; i < n; i++) {
if (a[i] == 'S' && b[i] == 'S')
res += 'S';
else if (a[i] == 'E' && b[i] == 'E')
res += 'E';
else if (a[i] == 'T' && b[i] == 'T')
res += 'T';
else if (a[i] != 'S' && b[i] != 'S')
res += 'S';
else if (a[i] != 'T' && b[i] != 'T')
res += 'T';
else if (a[i] != 'E' && b[i] != 'E')
res += 'E';
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> A[i];
int m = 0;
for (int i = 1; i < n; i++) {
for (int j = i + 1; j <= n; j++) B[++m] = third(A[i], A[j]);
}
sort(A + 1, A + n + 1);
sort(B + 1, B + m + 1);
int res = 0, a = 1, b = 1;
while (a <= n && b <= m) {
if (A[a] < B[b])
a++;
else if (A[a] > B[b])
b++;
else {
res++;
b++;
}
}
cout << res / 3;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
int ans = 0;
for (int j = 0; j < n; j++) {
map<string, int> mp;
for (int l = j + 1; l < n; l++) {
mp[s[l]]++;
}
for (int l = j + 1; l < n; l++) {
mp[s[l]]--;
string req(k, 'E');
for (int i = 0; i < k; i++) {
if (s[j][i] == s[l][i]) {
req[i] = s[j][i];
} else {
if (s[j][i] == 'E') {
req[i] = 'T';
if (s[l][i] == 'T') {
req[i] = 'S';
}
} else if (s[j][i] == 'T') {
req[i] = 'E';
if (s[l][i] == 'E') {
req[i] = 'S';
}
} else {
req[i] = 'E';
if (s[l][i] == 'E') {
req[i] = 'T';
}
}
}
}
ans += mp[req];
}
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
for (int i = 0; i < t; i++) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 100;
const long long MOD = 1e9 + 7;
const long long INF = 1e16;
long long cnt[32][4];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
long long n, k;
cin >> n >> k;
string a[n + 1];
for (int i = 0; i < n; i++) cin >> a[i];
map<string, long long> m;
for (int i = 0; i < n; i++) {
string xd;
for (int x = 0; x < k; x++) {
if (a[i][x] == 'S')
xd += '0';
else if (a[i][x] == 'E')
xd += '1';
else
xd += '2';
}
m[xd]++;
}
long long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string xd;
bool diff = false;
for (int x = 0; x < k; x++) {
if (a[i][x] == a[j][x]) {
if (a[i][x] == 'S')
xd += '0';
else if (a[i][x] == 'E')
xd += '1';
else
xd += '2';
} else {
string missing;
missing += a[i][x];
missing += a[j][x];
if (missing[0] != 'E' && missing[1] != 'E') xd += '1';
if (missing[0] != 'S' && missing[1] != 'S') xd += '0';
if (missing[0] != 'T' && missing[1] != 'T') xd += '2';
}
}
ans += m[xd];
}
}
cout << ans / 3 << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, k;
cin >> n >> k;
map<string, long long> s;
string a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
s[a[i]] = i + 1;
}
long long ans = 0;
for (long long i = 0; i < n; i++) {
for (long long j = i + 1; j < n; j++) {
char p[k];
for (long long l = 0; l < k; l++) {
if (a[i][l] == a[j][l]) {
p[l] = a[i][l];
continue;
}
if (a[i][l] == 'S' || a[j][l] == 'S') {
if (a[i][l] == 'E' || a[j][l] == 'E')
p[l] = 'T';
else
p[l] = 'E';
} else
p[l] = 'S';
}
string ps(p);
if (s[ps.substr(0, k)] > j + 1) {
ans++;
}
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long T = 1;
while (T--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> graph;
vector<pair<int, pair<int, int>>> ans;
long long int arr[1001000];
long long int grid[1010][1010];
vector<string> vec;
unordered_map<string, int> M;
int solver(int K) {
int count = 0;
int n = vec.size();
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string key = "";
for (int k = 0; k < K; k++) {
if (vec[i][k] == vec[j][k]) {
key += vec[i][k];
} else {
key += vec[i][k] ^ vec[j][k] ^ 'S' ^ 'E' ^ 'T';
}
}
if (M[key] > j) {
count++;
}
}
}
return count;
}
int main() {
long long int n, k;
string s;
cin >> n >> k;
int i = 0;
while (i < n) {
cin >> s;
vec.push_back(s);
M[s] = i;
i++;
}
cout << solver(k) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, j, k, l, check, count = 0;
scanf("%d %d", &n, &m);
string str;
string c[n + 6];
for (i = 0; i < n; ++i) {
cin >> c[i];
}
map<string, int> cnt;
for (i = 0; i < n; ++i) {
for (j = i + 1; j < n; ++j) {
str = "";
for (l = 0; l < m; ++l) {
if (c[i][l] == c[j][l])
str += c[i][l];
else
str += 'S' + 'E' + 'T' - c[i][l] - c[j][l];
}
if (cnt.find(str) != cnt.end()) count += cnt[str];
}
cnt[c[i]]++;
}
printf("%d", count);
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int INF = 1e18 + 7;
const int MOD = 1e9 + 7;
int64_t n, k, ans;
string a[1505];
unordered_map<string, bool> m;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for (int32_t i = 0; i < (n); ++i) {
cin >> a[i];
m[a[i]] = true;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string temp;
for (int z = 0; z < k; z++) {
if (a[i][z] == a[j][z])
temp += a[i][z];
else {
if (a[i][z] != 'S' && a[j][z] != 'S') temp += 'S';
if (a[i][z] != 'E' && a[j][z] != 'E') temp += 'E';
if (a[i][z] != 'T' && a[j][z] != 'T') temp += 'T';
}
}
if (m[temp] > 0) {
ans++;
}
}
}
cout << ans / 3 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int a, b, c, d, e, f, g, i, j, k, m, n, o,
q = 0, r = 0, u, w, z, s, t, p = 2, x, y, temp, v, h, l;
long long int ans = 0;
string s1, s4, s5, s6, s7, s8, s9;
vector<long long int> v1, v2, v3, v4, v5, v6;
double f1, f2, f3, f4, f5, f6;
char c4, c5, c6;
long long int gcd(long long int m, long long int n) {
if (m > n) {
if (m % n == 0) {
return n;
} else {
m = m % n;
return gcd(n, m);
}
} else {
if (n % m == 0) {
return m;
} else {
n = n % m;
return gcd(n, m);
}
}
}
long long int power(long long int a) {
long long int a1 = 1;
for (i = 0; i < a; i++) {
a1 = 2 * a1;
a1 = a1 % 1000000007;
}
return a1;
}
long long int prime(long long int a) {
int temp = 0;
for (long long int i = 2; i < (sqrt(n)) + 1; i++) {
if ((a % i) == 0) {
temp = 1;
}
}
return temp;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
t = 1;
while (t--) {
cin >> n >> m;
string a1[n], a2[m];
r = 0;
p = q = 0;
s = 0;
map<long long int, long long int> m1, m2, m3, m4;
for (i = 0; i < n; i++) cin >> a1[i];
for (i = 0; i < n; i++) {
map<string, long long int> ms1;
for (j = i + 1; j < n; j++) {
string s2;
for (k = 0; k < m; k++) {
if (a1[i][k] == a1[j][k]) {
s2.push_back(a1[i][k]);
} else {
p = q = r = 0;
if (a1[i][k] == 'S' || a1[j][k] == 'S') {
p = 1;
}
if (a1[i][k] == 'E' || a1[j][k] == 'E') q = 1;
if (a1[i][k] == 'T' || a1[j][k] == 'T') r = 1;
if (p == 0) s2.push_back('S');
if (q == 0) s2.push_back('E');
if (r == 0) s2.push_back('T');
}
}
ms1[s2]++;
if (ms1[a1[j]] > 0) {
s++;
}
}
}
cout << s;
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, mm, ans = 0;
cin >> n >> mm;
string a[n];
map<string, int> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string s = "";
for (int k = 0; k < mm; k++) {
char c = a[i][k], d = a[j][k];
if (c == d)
s += c;
else {
if (!(c == 'S' || d == 'S')) s += 'S';
if (!(c == 'T' || d == 'T')) s += 'T';
if (!(c == 'E' || d == 'E')) s += 'E';
}
}
if (a[i] == a[j]) {
if (m[s] > 2) ans++;
} else {
if (m[s]) ans++;
}
}
m[a[i]]++;
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1000005;
const long long SQRTN = 1003;
const long long LOGN = 22;
const double PI = acos(-1);
const long long INF = 1e16;
const long long MOD = 1000000007;
const long long FMOD = 998244353;
const double eps = 1e-9;
bool primes[100001];
long long spf[100001];
void sieve() {
primes[0] = primes[1] = false;
for (long long i = 1; i <= 100000; i++) {
spf[i] = i;
primes[i] = true;
}
spf[2] = 2;
for (long long i = 4; i <= 100000; i += 2) {
spf[i] = 2;
primes[i] = false;
}
for (long long i = 3; i * i <= 100000; i += 2) {
if (spf[i] == i) {
for (long long j = i * i; j <= 100000; j += i) {
if (spf[j] == j) spf[j] = i;
primes[j] = false;
}
}
}
return;
}
long long power(long long n, long long m, long long p) {
long long res = 1;
n = n % MOD;
while (m > 0) {
if (m & 1) {
res = ((res) % p * (n) % p) % p;
m--;
}
n = ((n) % p * (n) % p) % p;
m >>= 1;
}
return res;
}
long long N = 10000;
long long factorialNumInverse[100001];
long long naturalNumInverse[100001];
long long fact[100001];
void InverseofNumber(long long p) {
naturalNumInverse[0] = naturalNumInverse[1] = 1;
for (long long i = 2; i <= N; i++)
naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;
}
void InverseofFactorial(long long p) {
factorialNumInverse[0] = factorialNumInverse[1] = 1;
for (long long i = 2; i <= N; i++)
factorialNumInverse[i] =
(naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;
}
void factorial(long long p) {
fact[0] = 1;
for (long long i = 1; i <= N; i++) {
fact[i] = (fact[i - 1] * i) % p;
}
}
long long Binomial(long long N, long long R, long long p) {
long long ans =
((fact[N] * factorialNumInverse[R]) % p * factorialNumInverse[N - R]) % p;
return ans;
}
long long modInverse(long long n, long long p) { return power(n, p - 2, p); }
long long nCrModPFermat(long long n, long long r, long long p) {
if (n < r) return 0;
if (r == 0) return 1;
long long fac[n + 1];
fac[0] = 1;
for (long long i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
p;
}
void solvethetestcase();
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
for (long long testcase = 1; testcase < t + 1; testcase++) {
solvethetestcase();
}
}
long long n, m, a, b, c, zero, p, t1, t2, t, q, cnt;
string getString(string s1, string s2) {
string s = "";
long long k = s1.length();
for (long long i = 0; i < k; i++) {
if (s1[i] == s2[i])
s.push_back(s1[i]);
else
s.push_back('E' + 'T' + 'S' - s1[i] - s2[i]);
}
return s;
}
void solvethetestcase() {
long long k;
cin >> n >> k;
vector<string> vec(n);
map<string, long long> mi;
for (long long i = 0; i < n; i++) {
string s;
cin >> s;
vec[i] = s;
mi[s]++;
}
long long ans = 0;
for (long long i = 0; i < n; i++) {
string s1 = vec[i];
for (long long j = i + 1; j < n; j++) {
string s2 = vec[j];
ans += mi[getString(s1, s2)];
}
}
cout << ans / 3 << "\n";
return;
}
|
#include <bits/stdc++.h>
using namespace std;
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
inline long long gcd(long long a, long long b) {
a = ((a) < 0 ? -(a) : (a));
b = ((b) < 0 ? -(b) : (b));
while (b) {
a = a % b;
swap(a, b);
}
return a;
}
long long ext_gcd(long long A, long long B, long long* X, long long* Y) {
long long x2, y2, x1, y1, x, y, r2, r1, q, r;
x2 = 1;
y2 = 0;
x1 = 0;
y1 = 1;
for (r2 = A, r1 = B; r1 != 0;
r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y) {
q = r2 / r1;
r = r2 % r1;
x = x2 - (q * x1);
y = y2 - (q * y1);
}
*X = x2;
*Y = y2;
return r2;
}
inline long long modInv(long long a, long long m) {
long long x, y;
ext_gcd(a, m, &x, &y);
x %= m;
if (x < 0) x += m;
return x;
}
inline long long bigmod(long long a, long long p, long long m) {
long long res = 1 % m, x = a % m;
while (p) {
if (p & 1) res = (res * x) % m;
x = (x * x) % m;
p >>= 1;
}
return res;
}
const long long inf = 2147383647;
const long long mod = 1000000007;
const double pi = 2 * acos(0.0);
const double eps = 1e-11;
int N, K;
vector<string> V;
set<string> S;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> K;
for (int i = 0; i < N; i++) {
string str;
cin >> str;
V.push_back(str);
S.insert(str);
}
if (N < 3) {
cout << "0\n";
return 0;
}
long long cnt = 0;
for (int i = 0; i < V.size() - 1; i++) {
for (int j = i + 1; j < V.size(); j++) {
string T = "";
for (int k = 0; k < K; k++) {
if ((V[i][k] == 'S' && V[j][k] == 'S')) {
T += 'S';
} else if ((V[i][k] == 'E' && V[j][k] == 'E')) {
T += 'E';
} else if ((V[i][k] == 'T' && V[j][k] == 'T')) {
T += 'T';
} else if ((V[i][k] == 'S' && V[j][k] == 'E') ||
(V[i][k] == 'E' && V[j][k] == 'S')) {
T += 'T';
} else if ((V[i][k] == 'E' && V[j][k] == 'T') ||
(V[i][k] == 'T' && V[j][k] == 'E')) {
T += 'S';
} else if ((V[i][k] == 'S' && V[j][k] == 'T') ||
(V[i][k] == 'T' && V[j][k] == 'S')) {
T += 'E';
}
}
if (S.find(T) != S.end()) cnt++;
}
}
cout << cnt / 3 << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, k;
cin >> n >> k;
map<string, long long> s;
string a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
s[a[i]] = i + 1;
}
long long ans = 0;
for (long long i = 0; i < n; i++) {
for (long long j = i + 1; j < n; j++) {
char p[k + 1];
for (long long l = 0; l < k; l++) {
if (a[i][l] == a[j][l]) {
p[l] = a[i][l];
continue;
}
if (a[i][l] == 'S' || a[j][l] == 'S') {
if (a[i][l] == 'E' || a[j][l] == 'E')
p[l] = 'T';
else
p[l] = 'E';
} else
p[l] = 'S';
}
p[k] = NULL;
string ps(p);
if (s[ps] > j + 1) {
ans++;
}
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long T = 1;
while (T--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string func(char a, char b) {
if (a != 'S' && b != 'S') return "S";
if (a != 'E' && b != 'E') return "E";
if (a != 'T' && b != 'T') return "T";
}
map<string, long long int> mp;
string s[2005];
long long int ans = 0;
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> s[i];
mp[s[i]] = 1;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string temp = "";
for (int l = 0; l < k; l++) {
if (s[i][l] == s[j][l])
temp += s[i][l];
else
temp += func(s[i][l], s[j][l]);
}
ans += mp[temp];
}
}
cout << ans / 3;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, K;
cin >> n >> K;
vector<string> v(n);
unordered_map<string, int> ind;
for (int i = 0; i < n; i++) {
cin >> v[i];
ind[v[i]] = i;
}
long long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string t = "";
for (int k = 0; k < K; k++) {
if (v[i][k] == v[j][k])
t += v[i][k];
else
t += 'S' ^ 'E' ^ 'T' ^ v[i][k] ^ v[j][k];
}
if (ind.count(t) && ind[t] > j) ans++;
}
}
cout << ans << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, k;
char C[] = {'S', 'E', 'T'};
string s[1600], Search, second, T;
map<string, int> mp;
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> s[i];
mp[s[i]]++;
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
int cnt = 0;
mp[s[i]]--;
for (int j = i + 1; j <= n; j++) {
second = s[i];
T = s[j];
Search.clear();
for (int d = 0; d < k; d++) {
if (second[d] == T[d])
Search += second[d];
else
for (int g = 0; g < 3; g++) {
if (C[g] != second[d] && C[g] != T[d]) {
Search += C[g];
break;
}
}
}
if (mp.find(Search) != mp.end()) cnt += mp[Search];
}
ans += cnt / 2;
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
vector<string> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
map<string, int> mp;
for (int i = 0; i < n; i++) {
mp[v[i]] = i;
}
long long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string get = "";
for (int t = 0; t < k; t++) {
if (v[i][t] == v[j][t]) {
get += v[i][t];
} else {
if (v[i][t] == 'S') {
if (v[j][t] == 'E') {
get += 'T';
} else {
get += 'E';
}
} else if (v[i][t] == 'E') {
if (v[j][t] == 'S') {
get += 'T';
} else {
get += 'S';
}
} else {
if (v[j][t] == 'S') {
get += 'E';
} else {
get += 'S';
}
}
}
}
if (mp[get] > j) {
ans++;
}
}
}
cout << ans << "\n";
return;
}
signed main() {
auto start = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
solve();
}
auto stop = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char convert(char a, char b) {
if (a == b) return a;
string ans = "SET";
for (int i = 0; i < ans.size(); ++i)
if (ans[i] != a && ans[i] != b) return ans[i];
return 0;
}
int main() {
int n, k;
cin >> n >> k;
vector<string> strs(n);
for (auto& t : strs) cin >> t;
sort(strs.begin(), strs.end());
long long counter = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
string str = "";
for (int u = 0; u < k; ++u) str += convert(strs[i][u], strs[j][u]);
counter += upper_bound(strs.begin() + j + 1, strs.end(), str) -
lower_bound(strs.begin() + j + 1, strs.end(), str);
}
}
cout << counter;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int infinity = 9e18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
set<string> s;
string st;
vector<string> v(n);
map<string, int> m;
for (int i = 0; i < n; i++) {
cin >> v[i];
s.insert(v[i]);
m[v[i]] = i;
}
long long int total = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string s1 = "";
for (int p = 0; p < k; p++) {
if (v[i][p] == v[j][p])
s1 += v[i][p];
else {
s1 += ('S' + 'E' + 'T' - (v[j][p]) - (v[i][p]));
}
}
if (s.find(s1) != s.end()) {
if (m[s1] > j) {
total++;
}
}
}
}
cout << total;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<long long>;
template <class T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T>
istream &operator>>(istream &, vector<T> &);
template <class T>
ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U>
istream &operator>>(istream &, pair<T, U> &);
template <class T, class U>
ostream &operator<<(ostream &, const pair<T, U> &);
template <class T>
struct Inf {
static constexpr T inf() {
return std::numeric_limits<T>::has_infinity
? std::numeric_limits<T>::infinity()
: std::numeric_limits<T>::max();
}
};
template <>
struct Inf<int> {
static constexpr int inf() { return 0x3f3f3f3f; }
};
template <>
struct Inf<long long> {
static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; }
};
constexpr int INF = Inf<int>::inf();
constexpr ll BINF = Inf<ll>::inf();
int solve() {
int n, k;
cin >> n >> k;
vector<string> v(n);
cin >> v;
unordered_map<string, int> haha;
string hc = "SET";
auto gtt = [&](char x, char y) {
if (x == y) return x;
for (char c : hc)
if (c != x && c != y) return c;
return '?';
};
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string t(k, '?');
for (int z = 0; z < k; z++) t[z] = gtt(v[i][z], v[j][z]);
if (haha.count(t)) ans += haha[t];
}
haha[v[i]]++;
}
cout << ans << endl;
return 0;
}
int main() {
ios::sync_with_stdio(0);
solve();
return 0;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
for (auto it = v.begin(); it != v.end(); ++it) is >> *it;
return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto it = v.begin(); it != v.end();)
os << *it, os << " \n"[++it == v.end()];
return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
return is >> p.first >> p.second;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << p.first << ' ' << p.second;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1500 + 100;
string inp[MAX];
int main() {
int n, k;
scanf("%d %d", &n, &k);
long long res = 0;
map<string, int> mp;
for (int i = 0; i < n; ++i) {
char str[100];
scanf("%s", str);
string s(str);
inp[i] = s;
mp[s] += 1;
}
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
string search;
for (int l = 0; l < k; ++l) {
if (inp[i][l] == inp[j][l])
search += inp[i][l];
else
search += ('S' + 'E' + 'T') - (inp[i][l] + inp[j][l]);
}
res += mp[search];
if (search == inp[i]) res -= 2;
}
}
res /= 3;
printf("%lld", res);
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a > b) swap(a, b);
if (a == 0) return b;
return gcd(b % a, a);
}
long long powerMod(long long x, long long y) {
long long res = 1;
x %= 1000000007;
while (y > 0) {
if (y & 1) res = (res * x) % 1000000007;
y = y >> 1;
x = (x * x) % 1000000007;
}
return res % 1000000007;
}
string binary(long long s) {
string res = "";
while (s != 0) {
res += (char)('0' + s % 2);
s /= 2;
}
reverse(res.begin(), res.end());
return res;
}
char r(char a, char b) {
if (a == 'S' && b == 'T') return 'E';
if (a == 'S' && b == 'E') return 'T';
if (a == 'E' && b == 'T') return 'S';
swap(a, b);
if (a == 'S' && b == 'T') return 'E';
if (a == 'S' && b == 'E') return 'T';
if (a == 'E' && b == 'T') return 'S';
return '_';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
;
int n, m, i, j, k, l, p;
cin >> n >> m;
vector<string> a(n);
p = 0;
set<string> s;
for (i = 0; i < n; i++) {
cin >> a[i];
s.insert(a[i]);
}
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (i != j) {
string st = "";
for (k = 0; k < m; k++) {
if (a[i][k] == a[j][k])
st += a[i][k];
else
st += r(a[i][k], a[j][k]);
}
if (st != a[i] && st != a[j] && s.find(st) != s.end()) p++;
}
}
}
cout << p / 3 << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename T1>
T amax(T &a, T1 b) {
if (b > a) a = b;
return a;
}
template <typename T, typename T1>
T amin(T &a, T1 b) {
if (b < a) a = b;
return a;
}
const int mod = 1000000000 + 7;
const int N = 1000000 + 6;
const int maxn = 1e5 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
string s[n];
for (int i = 0; i < n; i++) cin >> s[i];
map<string, int> m;
for (int i = 0; i < n; i++) m[s[i]] = i;
sort(s, s + n);
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string t = "";
bool bo = true;
for (int z = 0; z < k; z++) {
if (s[i][z] == s[j][z]) {
t += s[i][z];
} else {
int temp = s[i][z] + s[j][z];
t += 'S' + 'E' + 'T' - temp;
}
}
if (bo) {
int temp = lower_bound(s + j + 1, s + n, t) - s;
if (s[temp] == t) ans++;
}
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
const long long int M = 1000000007;
const double pi = 3.1415926;
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
fastio();
int n, k;
cin >> n >> k;
string s[n];
unordered_map<string, int> m;
for (int i = 0; i < n; i++) {
cin >> s[i];
m[s[i]] = 1;
}
int c = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
string g;
if (i != j) {
for (int l = 0; l < k; l++) {
g += s[i][l] == s[j][l] ? s[i][l]
: 'S' + 'T' + 'E' - s[i][l] - s[j][l];
}
auto it = m.find(g);
if (it != m.end()) c++;
}
}
}
cout << c / 6;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string e[1505];
int n, K;
int main() {
ios::sync_with_stdio(false);
map<string, int> M;
string T;
int S = 'S' + 'E' + 'T';
long long ans = 0;
cin >> n >> K;
for (int i = 1; i <= n; ++i) cin >> e[i], M[e[i]]++;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
if (i == j) continue;
T = "";
for (int o = 0; o < K; ++o) {
if (e[i][o] == e[j][o])
T += e[i][o];
else {
T += (char)(S - e[i][o] - e[j][o]);
}
}
if (M.find(T) != M.end()) ans += M[T];
}
}
cout << ans / 3 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int i, n, k, r;
string t;
unordered_set<string> s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
for (cin >> n >> k; n--;) {
cin >> t;
for (auto x : s) {
for (i = k; i--;)
if (x[i] ^ t[i]) x[i] ^= 66 ^ t[i];
r += s.count(x);
}
s.insert(t);
}
cout << r / 2;
}
|
#include <bits/stdc++.h>
const int N = 3e5 + 5;
const long double pi = 3.141592653;
const long long mod = 1e9 + 9;
const long long MOD = 998244353;
const long long INF = 9223372036854775807LL;
using namespace std;
int dx[9] = {1, -1, 0, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 0, 1, -1, 1, -1, 1, -1, 0};
long long binexp(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b % 2) res = (res * a) % mod;
a = (a * a) % mod;
b = b / 2;
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
while (T--) {
int n, k, ans = 0;
cin >> n >> k;
vector<string> v(n);
set<long long> st;
for (int i = 0; i < n; i++) {
cin >> v[i];
long long hash = 0;
for (int j = 0; j < k; j++) {
v[i][j] = v[i][j] + 32;
hash += ((v[i][j] - 'a') * binexp(31, j)) % mod;
}
st.insert(hash);
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string s;
for (int l = 0; l < k; l++) {
if (v[i][l] == v[j][l])
s.push_back(v[i][l]);
else {
if (v[i][l] == 's' && v[j][l] == 'e')
s.push_back('t');
else if (v[i][l] == 's' && v[j][l] == 't')
s.push_back('e');
else if (v[i][l] == 'e' && v[j][l] == 't')
s.push_back('s');
else if (v[i][l] == 'e' && v[j][l] == 's')
s.push_back('t');
else if (v[i][l] == 't' && v[j][l] == 's')
s.push_back('e');
else if (v[i][l] == 't' && v[j][l] == 'e')
s.push_back('s');
}
}
long long hash = 0;
for (int l = 0; l < k; l++)
hash += ((s[l] - 'a') * binexp(31, l)) % mod;
if (st.find(hash) != st.end()) ans++;
}
}
cout << ans / 3;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1600;
map<string, int> mp;
string s[maxn];
void AC() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> s[i];
mp[s[i]]++;
}
int res = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++) {
string tmp = "";
for (int q = 0; q < k; q++) {
if (s[i][q] == s[j][q])
tmp += s[i][q];
else
tmp += 'S' + 'E' + 'T' - s[i][q] - s[j][q];
}
if (mp.count(tmp)) res += mp[tmp];
}
cout << res / 3 << endl;
}
int main() {
AC();
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.