text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<string> arr(n); map<string, int> hashmap; string s1, s2, s3; bool flag; for (int i = 0; i < n; i++) { cin >> arr[i]; hashmap[arr[i]] = 1; } int ans = 0; for (int p = 0; p < n; p++) { s1 = arr[p]; for (int q = p + 1; q < n; q++) { s2 = arr[q]; s3 = ""; for (int i = 0; i < k; i++) { if (s1[i] == s2[i]) s3 += s1[i]; else { if ((s1[i] == 'S' && s2[i] == 'E') || (s1[i] == 'E' && s2[i] == 'S')) s3 += 'T'; else if ((s1[i] == 'E' && s2[i] == 'T') || (s1[i] == 'T' && s2[i] == 'E')) s3 += 'S'; else if ((s1[i] == 'S' && s2[i] == 'T') || (s1[i] == 'T' && s2[i] == 'S')) s3 += 'E'; } } if (hashmap[s3] == 1) ans += 1; } } cout << (ans / 3) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; map<string, int> tempUsed; map<string, int> used; int main() { long long hash[1501]; int n, k; cin >> n >> k; string cards[1501]; for (int i = 0; i < n; i++) { cin >> cards[i]; for (int j = 0; j < k; j++) { if (cards[i][j] == 'S') cards[i][j] = 'A'; if (cards[i][j] == 'E') cards[i][j] = 'B'; if (cards[i][j] == 'T') cards[i][j] = 'C'; } used[cards[i]]++; } long long ans = 0; for (int i = 0; i < n - 1; i++) { used[cards[i]]--; tempUsed = used; for (int j = i + 1; j < n; j++) { string create; tempUsed[cards[j]]--; for (int l = 0; l < k; l++) { if (cards[i][l] == cards[j][l]) create.push_back(cards[i][l]); else if (cards[i][l] != 'A' && cards[j][l] != 'A') create.push_back('A'); else if (cards[i][l] != 'B' && cards[j][l] != 'B') create.push_back('B'); else create.push_back('C'); } ans += max(tempUsed[create], 0); } } printf("%lld", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int 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]); } int res = 0; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { string str(k, ' '); for (int u = 0; u < k; ++u) { if (v[i][u] == v[j][u]) { str[u] = v[i][u]; } else { int ch = 'E' + 'S' + 'T'; ch -= v[i][u]; ch -= v[j][u]; str[u] = static_cast<char>(ch); } } if (s.count(str) > 0) { ++res; } } } cout << res / 3 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; char diff(char a, char b) { if (a > b) swap(a, b); if (a == 'E' && b == 'S') return 'T'; if (a == 'E' && b == 'T') return 'S'; return 'E'; } int main() { string s; int n, m; cin >> n >> m; string arr[1510]; map<string, int> mp; for (int i = 0; i < n; i++) { cin >> arr[i]; mp[arr[i]] = 1; ; } int ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { string tmp = ""; for (int k = 0; k < m; k++) { if (arr[i][k] == arr[j][k]) { tmp += arr[i][k]; } else { tmp += diff(arr[i][k], arr[j][k]); } } if (mp[tmp] == 1) { ans++; } } } printf("%d\n", ans / 3); 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 (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; using ll = long long; using pii = pair<int, int>; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; map<string, int> mp; map<pair<char, char>, char> conv; int main() { cin.tie(0); ios::sync_with_stdio(0); conv[{'S', 'S'}] = 'S'; conv[{'E', 'E'}] = 'E'; conv[{'T', 'T'}] = 'T'; conv[{'S', 'E'}] = 'T'; conv[{'E', 'S'}] = 'T'; conv[{'S', 'T'}] = 'E'; conv[{'T', 'S'}] = 'E'; conv[{'E', 'T'}] = 'S'; conv[{'T', 'E'}] = 'S'; int n, k; cin >> n >> k; vector<string> vt(n); for (int i = 0; i < n; i++) { cin >> vt[i]; mp[vt[i]] += 1; } ll ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { string &s1 = vt[i], &s2 = vt[j]; string x; for (int l = 0; l < k; l++) { x += conv[{s1[l], s2[l]}]; } if (mp.find(x) != mp.end()) { int y = mp[x]; ans += y; } } } cout << ans / 3; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int MOD = INF; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector<string> in(n); map<string, int> hs; for (int i = 0; i < n; ++i) { cin >> in[i]; hs[in[i]]++; } int sum = 'S' + 'E' + 'T'; int ans = 0; for (int a = 0; a < n; ++a) { for (int b = a + 1; b < n; ++b) { string another = ""; for (int i = 0; i < k; ++i) { if (in[a][i] == in[b][i]) { another += in[a][i]; } else { another += sum - in[a][i] - in[b][i]; } } if (hs.count(another)) { ans += hs[another]; } } } ans /= 3; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; array<string, 1510> arr; unordered_set<string> f; int n, k, t = int('S' + 'E' + 'T'); char get(char c1, char c2) { if (c1 == c2) return c1; return t - c1 - c2; } int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { cin >> arr[i]; f.insert(arr[i]); } int res = 0; for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) { string s = ""; for (int p = 0; p < k; p++) s.push_back(get(arr[i][p], arr[j][p])); if (f.count(s)) res++; } printf("%d\n", res / 3); }
#include <bits/stdc++.h> using namespace std; map<string, int> mp; int main() { int n, k; cin >> n >> k; string st[n + 1]; for (int i = 0; i < n; i++) { cin >> st[i]; mp[st[i]]++; } string st2 = "EST"; int ct = 0; set<string> se; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { string st1, s; vector<string> vs; for (int a = 0; a < k; a++) { if (st[i][a] == st[j][a]) { st1.push_back(st[i][a]); } else { for (int b = 0; b < 3; b++) { if (st[i][a] != st2[b] and st[j][a] != st2[b]) { st1.push_back(st2[b]); break; } } } } if (mp[st1] > 0) { vs.push_back(st[i]); vs.push_back(st[j]); vs.push_back(st1); sort(vs.begin(), vs.end()); s = vs[0] + vs[1] + vs[2]; int l = se.size(); se.insert(s); if (se.size() > l) { ct++; } } } } cout << ct << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, k, ans; string s[2001]; set<string> st; int main() { cin >> n >> k; for (int i = 0; i < n; ++i) cin >> s[i]; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { string t; for (int p = 0; p < k; ++p) { if (s[i][p] == s[j][p]) { t += s[i][p]; } else { string r = string() + s[i][p] + s[j][p]; if (r == "SE" || r == "ES") t += 'T'; else if (r == "ET" || r == "TE") t += 'S'; else if (r == "ST" || r == "TS") t += 'E'; } } if (st.count(t)) ans++; } st.insert(s[i]); } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const double PI = 3.14159265358979323846; const int INF = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, diff; cin >> n >> diff; vector<string> v; string s; map<string, long long int> mp; for (int i = 0; i < n; i++) { cin >> s; v.push_back(s); mp[s]++; } long long int c = 0; bool ok = false; string cur; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { cur = ""; for (int k = 0; k < diff; k++) { if (v[i][k] == v[j][k]) cur += v[i][k]; else { if ((v[i][k] == 'S' && v[j][k] == 'E') || (v[j][k] == 'S' && v[i][k] == 'E')) cur += 'T'; else if ((v[i][k] == 'S' && v[j][k] == 'T') || (v[j][k] == 'S' && v[i][k] == 'T')) cur += 'E'; else cur += 'S'; } } c += mp[cur]; } } cout << c / 3; }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int64_t n, k, i, j, w; cin >> n >> k; string v[n]; set<string> g; for (i = 0; i < n; i++) { cin >> v[i]; g.insert(v[i]); } int64_t sum = 0; char t[3] = {'S', 'E', 'T'}; for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { string d; for (w = 0; w < k; w++) { if (v[i][w] == v[j][w]) { d += v[i][w]; } else { for (int64_t q = 0; q < 3; q++) { if (v[i][w] != t[q] && v[j][w] != t[q]) { d += t[q]; break; } } } } if (g.count(d)) sum++; } } cout << sum / 3 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long INF = 1e9 + 5; const double eps = 1e-7; const double PI = acos(-1.0); inline void debug_vi(vector<int> a) { for (long long i = (long long)(0); i < (long long)(a.size()); i++) cout << a[i] << " "; } inline void debug_vll(vector<long long> a) { for (long long i = (long long)(0); i < (long long)(a.size()); i++) cout << a[i] << " "; } inline void print_case(int tn) { cout << "Case #" << tn << ": "; } template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; template <typename T> using maxpq = priority_queue<T>; int n, k; vector<string> arr; set<string> s; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); clock_t clk = clock(); cin >> n >> k; arr.resize(n); for (long long i = (long long)(0); i < (long long)(n); i++) { cin >> arr[i]; s.insert(arr[i]); } int res = 0; for (long long i = (long long)(0); i < (long long)(n); i++) { for (long long j = (long long)(i + 1); j < (long long)(n); j++) { string target; for (long long p = (long long)(0); p < (long long)(k); p++) { if (arr[i][p] == arr[j][p]) { target.push_back(arr[i][p]); } else { vector<char> options = {'S', 'E', 'T'}; for (char c : options) { if (arr[i][p] == c || arr[j][p] == c) continue; target.push_back(c); } } } int minus = (target == arr[i]) + (target == arr[j]); res += s.count(target) - minus; } } cout << res / 3; cerr << "\n" << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << "\n"; 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 > x2) swap(x1, x2); if (x1 == 'E' && x2 == 'T') t += 'S'; if (x1 == 'S' && x2 == 'T') t += 'E'; if (x1 == 'E' && x2 == 'S') 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> using namespace std; int main() { int n, k; string s; std::vector<string> cards; std::map<string, bool> card_bank; 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[s] = true; } 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[aux_card]) ans++; } } printf("%d\n", ans / 3); }
#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 s1 = v[i]; string s2 = v[j]; string get = ""; for (int i = 0; i < k; i++) { if (s1[i] == s2[i]) { get += s1[i]; } else { if (s1[i] == 'S') { if (s2[i] == 'E') { get += 'T'; } else { get += 'E'; } } else if (s1[i] == 'E') { if (s2[i] == 'S') { get += 'T'; } else { get += 'S'; } } else { if (s2[i] == '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; int main() { int n, k; string s; std::vector<string> cards; std::map<string, bool> card_bank; 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[s] = true; } 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[aux_card]) ans++; } } printf("%d\n", ans / 3); }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t = 1; while (t--) { long long n, k, ans = 0, ans2 = 0; cin >> n >> k; vector<string> v; map<string, long long> m; map<string, long long>::iterator p1, p2; for (long long i = 0; i < n; ++i) { string s; cin >> s; v.push_back(s); m[s]++; } for (p1 = m.begin(); p1 != m.end(); ++p1) { if ((p1->second) >= 3) { long long t = p1->second; ans2 += ((t * (t - 1) * (t - 2)) / 6); } } for (p1 = m.begin(); p1 != m.end(); ++p1) { p1++; if (p1 == m.end()) { break; } p2 = p1; p1--; for (; p2 != m.end(); p2++) { string u, v, w = ""; u = p1->first; v = p2->first; for (long long i = 0; i < u.size(); ++i) { if (u[i] == v[i]) { w += v[i]; } else if ((u[i] == 'S' && v[i] == 'T') || (v[i] == 'S' && u[i] == 'T')) { w += 'E'; } else if ((u[i] == 'S' && v[i] == 'E') || (v[i] == 'S' && u[i] == 'E')) { w += 'T'; } else { w += 'S'; } } if (m.find(w) != m.end()) { ans += (m[u] * m[v] * m[w]); } } } ans /= 3; cout << ans + ans2 << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; string tab[1507]; map<string, int> sett; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> tab[i]; sett[tab[i]] = 1; } int ile = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { string x; for (int z = 0; z < k; z++) { if (tab[i][z] == tab[j][z]) x += tab[i][z]; else { x += 'S' + 'E' + 'T' - tab[i][z] - tab[j][z]; } } if (sett[x]) ile++; } } cout << ile / 3; }
#include <bits/stdc++.h> using ll = long long; using namespace std; int main() { ll n, k; cin >> n >> k; if (n < 3) { cout << 0 << endl; return 0; } vector<string> s(n); for (int i = 0; i < n; i++) cin >> s[i]; ll ans = 0; sort(s.begin(), s.end()); for (int i = 0; i < n - 2; i++) { for (int j = i + 1; j < n - 1; j++) { string key = ""; for (int l = 0; l < k; l++) { if (s[i][l] == s[j][l]) { key += s[i][l]; } else { if (s[i][l] != 'S' && s[j][l] != 'S') { key += 'S'; } else if (s[i][l] != 'E' && s[j][l] != 'E') { key += 'E'; } else if (s[i][l] != 'T' && s[j][l] != 'T') { key += 'T'; } } } bool find = binary_search(s.begin() + j + 1, s.end(), key); if (find) ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; void solve() { int n, kk; cin >> n >> kk; vector<string> v(n); unordered_map<string, int> mp; for (int i = 0; i < n; i++) { cin >> v[i]; mp[v[i]]++; } int ans = 0; string req; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { req = ""; for (int k = 0; k < kk; k++) { if (v[i][k] == v[j][k]) req.push_back(v[i][k]); else { if (v[i][k] == 'T' && v[j][k] == 'T') req.push_back('T'); if (v[i][k] == 'S' && v[j][k] == 'S') req.push_back('S'); if (v[i][k] == 'E' && v[j][k] == 'E') req.push_back('E'); if (v[i][k] == 'T' && v[j][k] == 'S') req.push_back('E'); if (v[i][k] == 'S' && v[j][k] == 'T') req.push_back('E'); if (v[i][k] == 'T' && v[j][k] == 'E') req.push_back('S'); if (v[i][k] == 'E' && v[j][k] == 'T') req.push_back('S'); if (v[i][k] == 'S' && v[j][k] == 'E') req.push_back('T'); if (v[i][k] == 'E' && v[j][k] == 'S') req.push_back('T'); } } if (mp[req]) ans++; } } cout << ans / 3 << endl; } signed main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; string s[1600]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int ans = 0; cin >> n >> k; for (int i = 0; i < n; i++) cin >> s[i]; sort(s, s + n); for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) { string want; for (int l = 0; l < k; l++) { if (s[i][l] == s[j][l]) want += s[i][l]; else { char c = 'S' - s[i][l] + 'E' - s[j][l] + 'T'; want += c; } } auto it = lower_bound(s + j + 1, s + n, want) - s; if (it >= n || want.compare(s[it])) continue; ans++; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; long long int add(long long int a, long long int b) { return ((a % 1000000007 + b % 1000000007) % 1000000007); } long long int mult(long long int a, long long int b) { return (((a % 1000000007) * (b % 1000000007)) % 1000000007); } long long int gcdExtended(long long int a, long long int b, long long int *x, long long int *y) { if (a == 0) { *x = 0, *y = 1; return b; } long long int x1, y1; long long int gcd = gcdExtended(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd; } long long int modInverse(long long int b, long long int m) { long long int x, y; long long int g = gcdExtended(b, m, &x, &y); if (g != 1) return -1; return (x % m + m) % m; } long long int modDivide(long long int a, long long int b, long long int m) { a = a % m; int inv = modInverse(b, m); return (inv * a) % m; } long long int power(long long int a, long long int n) { long long int ans = 1; while (n > 0) { long long int lastbit = (n & 1); if (lastbit) ans *= a; a *= a; n >>= 1; } return ans; } int sieveo(long long int n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); long long int ans = 0; for (long long int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (long long int i = p * p; i <= n; i += p) prime[i] = false; } } for (long long int p = 2; p <= n; p++) if (prime[p]) ans++; return ans; } void primesieve(long long int N, long long int s[]) { vector<bool> prime(N + 1, false); for (long long int i = 2; i <= N; i += 2) s[i] = 2; for (long long int i = 3; i <= N; i += 2) { if (prime[i] == false) { s[i] = i; for (long long int j = i; j * i <= N; j += 2) { if (prime[i * j] == false) { prime[i * j] = true; s[i * j] = i; } } } } } void primefactor(long long int N) { long long int s[N + 1]; primesieve(N, s); long long int curr = s[N]; long long int cnt = 1; while (N > 1) { N /= s[N]; if (curr == s[N]) { cnt++; continue; } curr = s[N]; cnt = 1; } } void solve() { long long int n, f; cin >> n >> f; string s[n]; map<string, long long int> mp; for (long long int i = 0; i < n; ++i) { cin >> s[i]; mp[s[i]] = i; } long long int ans = 0, count = 0; long long int alp = 'T' + 'S' + 'E'; for (long long int i = 0; i < n - 2; ++i) { for (long long int j = i + 1; j < n - 1; ++j) { string ch = ""; for (long long int l = 0; l < f; ++l) { if (s[i][l] == s[j][l]) ch += s[i][l]; else ch += alp - (s[i][l] + s[j][l]); } if (mp[ch] > j) ++ans; } } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); }
#include <bits/stdc++.h> using namespace std; int n, k; unordered_map<string, int> check; vector<string> words; int main() { ios::sync_with_stdio(false); cin.tie(NULL); if (fopen("input.in", "r")) { freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); } cin >> n >> k; words.resize(n); for (int i = 0; i < n; i++) { cin >> words[i]; check[words[i]]++; } int ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { string s = ""; for (int x = 0; x < k; x++) { if (words[i][x] == words[j][x]) { s += words[i][x]; } else { if (words[i][x] == 'S' && words[j][x] == 'E') s += 'T'; if (words[i][x] == 'S' && words[j][x] == 'T') s += 'E'; if (words[i][x] == 'E' && words[j][x] == 'S') s += 'T'; if (words[i][x] == 'E' && words[j][x] == 'T') s += 'S'; if (words[i][x] == 'T' && words[j][x] == 'S') s += 'E'; if (words[i][x] == 'T' && words[j][x] == 'E') s += 'S'; } } ans += check[s]; } } cout << ans / 3 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int find(string s, vector<string>& v, int l, int h) { while (l <= h) { int m = (l + h) / 2; if (v[m] == s) return 1; if (v[m] < s) l = m + 1; else h = m - 1; } return 0; } int main() { int n, k; cin >> n >> k; vector<string> v(n); for (int i = 0; i < n; ++i) cin >> v[i]; unordered_set<string> z; for (int i = 0; i < n; ++i) z.insert(v[i]); long long count = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i == j) continue; string s1 = v[i]; string s2 = v[j]; string s(k, 'x'); for (int x = 0; x < k; ++x) { if (s1[x] == s2[x]) s[x] = s1[x]; else { s[x] = 'S' + 'E' + 'T' - s1[x] - s2[x]; } } if (z.find(s) != z.end()) count++; } } cout << count / 6; return 0; }
#include <bits/stdc++.h> using namespace std; bool chmin(int64_t& a, const int64_t& b) { return b < a ? a = b, 1 : 0; } bool chmax(int64_t& a, const int64_t& b) { return a < b ? a = b, 1 : 0; } constexpr int pct(int x) { return __builtin_popcount(x); } constexpr int bits(int x) { return 31 - __builtin_clz(x); } const int N = 1e7 + 5; void run_case() { int n, k; cin >> n >> k; vector<string> second; int64_t c1 = 0, c2 = 0, c3 = 0; map<string, int64_t> m; set<string> st; for (int i = 0; i < n; i++) { string x; cin >> x; for (int j = 0; j < k; j++) { if (x[j] == 'E') x[j] = '0'; else if (x[j] == 'S') x[j] = '1'; else x[j] = '2'; } if (st.empty() || st.find(x) == st.end()) { second.push_back(x); st.insert(x); } m[x]++; } int64_t ans = 0; for (int i = 0; i < second.size(); i++) { for (int j = i + 1; j < second.size(); j++) { string temp = ""; for (int l = 0; l < k; l++) { if (second[i][l] == second[j][l]) temp += second[i][l]; else { if (second[i][l] == '0' && second[j][l] == '1') temp += '2'; if (second[i][l] == '0' && second[j][l] == '2') temp += '1'; if (second[i][l] == '1' && second[j][l] == '2') temp += '0'; if (second[i][l] == '1' && second[j][l] == '0') temp += '2'; if (second[i][l] == '2' && second[j][l] == '1') temp += '0'; if (second[i][l] == '2' && second[j][l] == '0') temp += '1'; } } ans += m[second[i]] * m[second[j]] * m[temp]; } } int64_t ans2 = 0; for (auto x : st) { ans2 += (m[x] * (m[x] - 1) * (m[x] - 2)) / 6; } cout << ans / 3 + ans2 << endl; } auto clk = clock(); int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; t = 1; while (t--) { run_case(); } return 0; }
#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'); } } if (ms1[a1[j]] > 0) { s = s + ms1[a1[j]]; } ms1[s2]++; } } cout << s; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> T ii() { T a; cin >> a; return a; } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; unordered_map<string, char> DIFF_CHAR = {{"ST", 'E'}, {"TS", 'E'}, {"SE", 'T'}, {"ES", 'T'}, {"ET", 'S'}, {"TE", 'S'}}; string createTriplet(string &a, string &b) { string ans = ""; int n = a.length(); for (auto i = (0); i <= (n - 1); i++) { if (a[i] == b[i]) ans.push_back(a[i]); else ans.push_back(DIFF_CHAR[string(1, a[i]) + string(1, b[i])]); } return ans; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vector<string> ar(n); for (auto &it : ar) cin >> it; unordered_map<string, int> dp; for (auto &it : ar) ++dp[it]; long long int ans = 0; for (auto i = (0); i <= (n - 1); i++) { for (auto j = (i + 1); j <= (n - 1); j++) { string cur = createTriplet(ar[i], ar[j]); ans += dp[cur]; } } cout << (ans / 3) << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; bool check(string& a, string& b, string& c, int& k) { for (int j = 0; j < k; j++) { int sum = 0; sum = a[j] - 'A' + b[j] - 'A' + c[j] - 'A'; if (sum == 12 || sum == 54 || sum == 57 || sum == 41) { continue; } else { return false; } } return true; } int main() { int n, k; cin >> n >> k; vector<string> a(n); unordered_set<string> hash; for (int i = 0; i < n; i++) { cin >> a[i]; hash.insert(a[i]); } int xors = 4 ^ 19 ^ 18; int count = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { string ans = a[i]; for (int l = 0; l < k; l++) { int sum = 0; if (a[i][l] == a[j][l]) { ans[l] = a[i][l]; } else { int rem = (a[i][l] - 'A') ^ (a[j][l] - 'A') ^ xors; ans[l] = 'A' + rem; } } count += (ans != a[i]) && (ans != a[j]) && (hash.find(ans) != hash.end()); } } cout << count / 3 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n = 0ll, k = 0ll, res = 0ll; cin >> n >> k; vector<string> v(n); unordered_map<string, long long int> m; for (long long int i = 0ll; i < n; ++i) { cin >> v[i]; ++m[v[i]]; } string s(k, 'X'); for (long long int i = 0ll; i < n; ++i) { for (long long int j = i + 1ll; j < n; ++j) { for (long long int l = 0ll; l < k; ++l) { if (v[i][l] == v[j][l]) s[l] = v[i][l]; else s[l] = 'S' ^ 'E' ^ 'T' ^ v[i][l] ^ v[j][l]; } res += m.count(s); } } cout << (res / 3ll); }
#include <bits/stdc++.h> using namespace std; template <typename T> inline T MIN(const T &a, const T &b) { return a < b ? a : b; } template <typename T> inline T MAX(const T &a, const T &b) { return a > b ? a : b; } template <typename T, typename... Args> inline T MIN(const T &a, const T &b, Args... args) { return MIN(MIN(a, b), args...); } template <typename T, typename... Args> inline T MAX(const T &a, const T &b, Args... args) { return MAX(MAX(a, b), args...); } const double eps = 1e-8; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const int dir[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1}; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; map<string, int> mp; string s[1600]; for (int i = 1; i <= n; i++) { cin >> s[i]; mp[s[i]]++; } auto judge = [](char a, char b) { if (a > b) swap(a, b); if (a == 'E' and b == 'S') return 'T'; if (a == 'S' and b == 'T') return 'E'; if (a == 'E' and b == 'T') return 'S'; }; int ans = 0; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { string res; for (int p = 0; p < k; p++) { if (s[i][p] == s[j][p]) { res += s[i][p]; continue; } res += judge(s[i][p], s[j][p]); } ans += mp[res]; } } cout << ans / 3 << '\n'; return 0; }
#include <bits/stdc++.h> long long dp[2002][2002]; long long exp(long long x, long long y) { long long r = 1; while (y) { if (y % 2 == 0) { x = (x * x); y = y / 2; } else { r = (r * x); x = (x * x); y = y / 2; } } return r; } int main() { long long i, j, t, n, k, count = 0, max = 0; char s[20002][31]; scanf("%lld %lld", &n, &k); for (i = 0; i < n; i++) { scanf("%s", s[i]); } for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { for (int l = 0; l < k; l++) { if (s[i][l] != s[j][l]) { dp[i][j] += exp(10, l); } } } } for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { for (long long l = j + 1; l < n; l++) { if (dp[i][j] == dp[j][l] && dp[i][l] == dp[i][j]) { count++; } } } } printf("%lld\n", count); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string aux; int n, k; cin >> n >> k; vector<string> lista; set<string> s; for (int i = 0; i < n; i++) { cin >> aux; lista.push_back(aux); s.insert(aux); } long long int coun = 0; for (int i = 0; i < n - 1; ++i) { for (int j = i + 1; j < n; ++j) { aux = ""; for (int l = 0; l < k; ++l) { if (lista[i][l] == lista[j][l]) aux += lista[i][l]; else aux += (char)('S' + 'E' + 'T' - lista[i][l] - lista[j][l]); } if (s.count(aux) != 0) ++coun; } } cout << coun / 3; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s[n + 1]; for (int i = 1; i < n + 1; i++) { cin >> s[i]; } int sum = 0; unordered_map<string, int> v; for (int i = 1; i < n + 1; i++) { v[s[i]]++; } for (int i = 1; i < n + 1; i++) { v[s[i - 1]]--; for (int j = i + 1; j < n + 1; j++) { v[s[j - 1]]--; string raw; for (int q = 0; q < k; q++) { if (s[i][q] == s[j][q]) raw.push_back(s[j][q]); else { int c1, c2, c3; c1 = (s[i][q] == 'S' || s[j][q] == 'S') ? 1 : 0; c2 = (s[i][q] == 'E' || s[j][q] == 'E') ? 1 : 0; c3 = (s[i][q] == 'T' || s[j][q] == 'T') ? 1 : 0; if (!c1) raw.push_back('S'); else if (!c2) raw.push_back('E'); else if (!c3) raw.push_back('T'); } } sum += v[raw]; } for (int j = i + 1; j < n + 1; j++) v[s[j - 1]]++; } cout << sum << "\n"; }
#include <bits/stdc++.h> using namespace std; inline long long add(long long a, long long b) { a += b; if (a >= 1000000007) a -= 1000000007; return a; } inline long long sub(long long a, long long b) { a -= b; if (a < 0) a += 1000000007; return a; } inline long long mul(long long a, long long b) { return (long long)((long long)a * b % 1000000007); } long long fast_power(long long base, long long power) { long long result = 1; while (power > 0) { if (power % 2 == 1) { result = (result * base); } base = (base * base); power = power / 2; } return result; } long long min(long long a, long long b) { return a > b ? b : a; } long long max(long long a, long long b) { return a > b ? a : b; } void SieveOfEratosthenes(long long n, set<long long> &s) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (long long p = 2; p <= n; p++) if (prime[p]) s.insert(p * p); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); { long long n, k, ans = 0; cin >> n >> k; vector<string> s; unordered_set<string> us; string tmp; for (long long i = 0; i < n; i++) { cin >> tmp; s.push_back(tmp); us.insert(tmp); } for (long long i = 0; i < n - 1; i++) { for (long long j = i + 1; j < n; j++) { string s1 = s[i]; for (long long m = 0; m < k; m++) { if (s[i][m] == s[j][m]) { s1[m] = s[i][m]; } else if (s[i][m] != s[j][m]) { if (s[i][m] == 'S') { if (s[j][m] == 'E') { s1[m] = 'T'; } else if (s[j][m] == 'T') { s1[m] = 'E'; } } else if (s[i][m] == 'E') { if (s[j][m] == 'S') { s1[m] = 'T'; } else if (s[j][m] == 'T') { s1[m] = 'S'; } } else if (s[i][m] == 'T') { if (s[j][m] == 'S') { s1[m] = 'E'; } else if (s[j][m] == 'E') { s1[m] = 'S'; } } } } if (us.find(s1) != us.end()) { ans += 1; } } } cout << ans / 3 << "\n"; } }
#include <bits/stdc++.h> using namespace std; vector<long long int> primes; bool specialPrimeNumbers(long long int n, long long int k) { for (long long int i = 0; i < primes.size(); i++) { for (long long int j = 0; j < i; j++) { if (primes[i] + primes[j] == n) { return true; } } } return false; } bool cmp(pair<int, int> p, pair<int, int> p1) { return p.first < p1.first; } class edge { public: int a, b; }; struct subset { int parent; int rank; }; int find(struct subset subsets[], int i) { if (subsets[i].parent != i) subsets[i].parent = find(subsets, subsets[i].parent); return subsets[i].parent; } void Union(struct subset subsets[], int x, int y) { int xroot = find(subsets, x); int yroot = find(subsets, y); if (subsets[xroot].rank < subsets[yroot].rank) subsets[xroot].parent = yroot; else if (subsets[xroot].rank > subsets[yroot].rank) subsets[yroot].parent = xroot; else { subsets[yroot].parent = xroot; subsets[xroot].rank++; } } void dfs(vector<int> edges[], int a, int b, int visit[], map<int, vector<int>> &mp) { visit[a] = 1; for (auto i : edges[a]) { if (visit[i] == 1) { continue; } else { mp[b].push_back(i); dfs(edges, i, b + 1, visit, mp); } } } string result(string second) { return second; } void simpleSieve(int limit) { bool mark[limit + 1]; memset(mark, true, sizeof(mark)); for (int p = 2; p * p < limit; p++) { if (mark[p] == true) { for (int i = p * 2; i < limit; i += p) mark[i] = false; } } for (int p = 2; p < limit; p++) { if (mark[p] == true) { primes.push_back(p); } } } void segmentedSieve(int n) { int limit = floor(sqrt(n)) + 1; simpleSieve(limit); int low = limit; int high = 2 * limit; while (low < n) { if (high >= n) high = n; bool mark[limit + 1]; memset(mark, true, sizeof(mark)); for (int i = 0; i < primes.size(); i++) { int loLim = floor(low / primes[i]) * primes[i]; if (loLim < low) loLim += primes[i]; for (int j = loLim; j < high; j += primes[i]) mark[j - low] = false; } for (int i = low; i < high; i++) if (mark[i - low] == true) primes.push_back(i); low = low + limit; high = high + limit; } } int dfs(vector<long long int> edges[], long long int &u, long long int v) { for (auto i : edges[u]) { if (i != v) { u = i; return 1; } } return 0; } int dfs1(vector<long long int> edges[], long long int &u, long long int v, map<int, int> &mp) { for (auto i : edges[u]) { if (i == v) { u = i; return 1; } else { if (mp.count(i) > 0) continue; u = i; mp.insert({i, 1}); } } return 0; } long long int pairORSum(long long int arr[], int n) { long long int ans = 0; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) ans += arr[i] ^ arr[j]; return ans % 1000000007; } long long int power(long long int x, long long int y, long long int p) { long long int 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 int sumXOR(long long int arr[], long long int n) { long long int sum = 0; long long int zero[62] = {0}, one[62] = {0}; long long int maxi = 0; for (int i = 0; i < n; i++) { long long int count = 0; while (count < 62) { if (arr[i] % 2 == 0) { zero[count]++; } else { one[count]++; } arr[i] = arr[i] / 2; maxi = max(count, maxi); count++; } } long long int ans = 0; for (int i = 0; i <= maxi; i++) { ans = (ans + ((zero[i] * one[i]) % 1000000007) * (power(2, i, 1000000007)) % 1000000007) % 1000000007; } return ans; } long double distance(long long int x, long long int y, long long int x1, long long int y1) { return (sqrt(pow(abs(x - x1), 2) + pow(abs(y - y1), 2))); } long double fact(int n) { if (n == 1) { return 1; } return n * fact(n - 1); } void solve1() {} bool cmp1(pair<long long int, long long int> p, pair<long long int, long long int> p1) { return (p.second < p1.second); } long long int set_bit(long long int n) { long long int count = 0; while (n != 0) { if (n % 2 == 1) { count++; } n = n / 2; } return count; } long long int pow1(long long int a, long long int b) { if (b == 0) return 1; return a * pow1(a, b - 1); } long long int ans(string second[], int n, int m, int dp[], int curr, char flag, char flag2) { return 0; } bool cmp2(string second, string s1) { return second.length() > s1.length(); } int findMinLength(string arr[], int n) { int min = INT_MAX; for (int i = 0; i <= n - 1; i++) if (arr[i].length() < min) min = arr[i].length(); return (min); } bool allContainsPrefix(string arr[], int n, string str, int start, int end) { for (int i = 0; i <= n - 1; i++) for (int j = start; j <= end; j++) if (arr[i][j] != str[j]) return (false); return (true); } string commonPrefix(string arr[], int n) { int index = findMinLength(arr, n); string prefix; int low = 0, high = index; while (low <= high) { int mid = low + (high - low) / 2; if (allContainsPrefix(arr, n, arr[0], low, mid)) { prefix = prefix + arr[0].substr(low, mid - low + 1); low = mid + 1; } else high = mid - 1; } return (prefix); } bool cmp4(pair<pair<long long int, long long int>, long long int> p, pair<pair<long long int, long long int>, long long int> p1) { return p.first.first < p1.first.first; } long long int sub_mod(long long int x, long long int y) { x -= y; if (x < 0) return x + 1000000007; return x; } long long int add_mod(long long int x, long long int y) { x += y; if (x >= 1000000007) return x - 1000000007; return x; } long long int multi_mod(long long int a, long long int b) { return (a * b) % 1000000007; } long long int gcdExtended(long long int a, long long int b, long long int *x, long long int *y) { if (a == 0) { *x = 0, *y = 1; return b; } long long int x1, y1; long long int gcd = gcdExtended(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd; } long long int inv_mod2(long long int b, long long int m) { long long int x, y; long long int g = gcdExtended(b, m, &x, &y); if (g != 1) return -1; return (x % m + m) % m; } long long int inv_mod(long long int a) { long long int b = 1000000007, p = 1, q = 0; while (b) { long long int c = a / b, d = a; a = b; b = d % b; d = p; p = q; q = d - c * q; } return (p + 1000000007) % 1000000007; } void solve() { long long int n, k; cin >> n >> k; string v[n]; int i; map<string, int> mp; for (i = 0; i < n; i++) { cin >> v[i]; mp[v[i]]++; } long long int res = 0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { string s1 = ""; for (int z = 0; z < k; z++) { if (v[i][z] == v[j][z]) { s1 += v[i][z]; } else { if (v[i][z] == 'S' && v[j][z] == 'E' || (v[i][z] == 'E' && v[j][z] == 'S')) { s1 += "T"; } if (v[i][z] == 'E' && v[j][z] == 'T' || (v[i][z] == 'T' && v[j][z] == 'E')) { s1 += "S"; } if (v[i][z] == 'T' && v[j][z] == 'S' || (v[i][z] == 'S' && v[j][z] == 'T')) { s1 += "E"; } } } res += mp[s1]; } } cout << res / 3 << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; for (int i = 0; i < t; i++) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; string e[1505]; int n, K; map<string, int> M; int main() { ios::sync_with_stdio(false); 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; string 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]); } } ans += M[T]; } } cout << ans / 3 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; map<string, int> tempUsed; map<string, int> used; int main() { long long hash[1501]; int n, k; cin >> n >> k; string cards[1501]; for (int i = 0; i < n; i++) { cin >> cards[i]; used[cards[i]]++; } long long ans = 0; for (int i = 0; i < n - 1; i++) { used[cards[i]]--; tempUsed = used; for (int j = i + 1; j < n; j++) { string create; tempUsed[cards[j]]--; for (int l = 0; l < k; l++) { if (cards[i][l] == cards[j][l]) create.push_back(cards[i][l]); else if (cards[i][l] != 'S' && cards[j][l] != 'S') create.push_back('S'); else if (cards[i][l] != 'E' && cards[j][l] != 'E') create.push_back('E'); else create.push_back('T'); } ans += max(tempUsed[create], 0); } } printf("%lld", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; int n, k; string s[1505]; int main() { while (cin >> n >> k) { map<string, long long> m; for (int i = 0; i < n; i++) cin >> s[i], m[s[i]]++; long long ans = 0; for (int i = 0; i < n; i++) { m[s[i]]--; for (int j = i + 1; j + 1 < n; j++) { m[s[j]]--; string ss; for (int z = 0; z < k; z++) { if ((s[i][z] == s[j][z])) { ss += s[i][z]; } else { if (s[i][z] != 'S' && s[j][z] != 'S') ss += 'S'; if (s[i][z] != 'E' && s[j][z] != 'E') ss += 'E'; if (s[i][z] != 'T' && s[j][z] != 'T') ss += 'T'; } } if (m.find(ss) != m.end()) { ans += m[ss]; } } for (int j = i + 1; j + 1 < n; j++) m[s[j]]++; } cout << ans << endl; } }
#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 { if (ff[i] == 'S' and ss[i] == 'E') word += 'T'; else if (ff[i] == 'E' and ss[i] == 'S') word += 'T'; else if (ff[i] == 'E' and ss[i] == 'T') word += 'S'; else if (ff[i] == 'T' and ss[i] == 'E') word += 'S'; else if (ff[i] == 'S' and ss[i] == 'T') word += 'E'; else word += 'E'; } } } int main() { long long n, i, j, k, cnt; cin >> n >> k; for (i = 0; i < n; i++) { cin >> str[i]; mp[str[i]] = 1; } for (i = 0, cnt = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if (i != j) { call(str[i], str[j], k); if (mp[word]) cnt++; word.clear(); } } } cout << cnt / 3 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; if (n < 3) { cout << 0; return 0; } vector<string> a(n); unordered_map<string, bool> gg; for (int i = 0; i < n; ++i) { cin >> a[i]; gg[a[i]] = 1; } int ans = 0; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { string need; for (int x = 0; x < k; ++x) { if (a[i][x] == a[j][x]) { need += a[i][x]; } else { if ((a[i][x] == 'S' || a[j][x] == 'S') && (a[i][x] == 'E' || a[j][x] == 'E')) { need += 'T'; } if ((a[i][x] == 'E' || a[j][x] == 'E') && (a[i][x] == 'T' || a[j][x] == 'T')) { need += 'S'; } if ((a[i][x] == 'S' || a[j][x] == 'S') && (a[i][x] == 'T' || a[j][x] == 'T')) { need += 'E'; } } } ans += gg[need]; } } cout << ans / 3; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, ans; string s[1505], t; map<string, int> ma; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> s[i]; ma[s[i]]++; } sort(s + 1, s + 1 + n); for (int i = 1; i <= n; i++) { if (ma[s[i]] > 2 && s[i] != s[i - 1]) ans += ma[s[i]] - 2; } for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { t.clear(); for (int k = 0; k < m; k++) { if (s[i][k] == s[j][k]) t += s[i][k]; else t += ('S' + 'E' + 'T' - s[i][k] - s[j][k]); } if (t < s[i] && t < s[j]) ans += ma[t]; } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; long long n, k, cnt = 0; set<string> str; bool check(string a, string b); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> k; vector<string> s(n); for (long i = 0; i < n; ++i) { cin >> s[i]; str.insert(s[i]); } if (n < 3) { cout << "0"; return 0; } else { for (long i = 0; i < n - 1; ++i) { for (long j = i + 1; j < n; ++j) { if (check(s[i], s[j])) { cnt++; } } } } cout << cnt / 3; return 0; } bool check(string a, string b) { string c = ""; for (long i = 0; i < k; ++i) { if (a[i] == b[i]) { c += a[i]; } else { if ((a[i] == 'S' && b[i] == 'E') || (a[i] == 'E' && b[i] == 'S')) { c += 'T'; } else if ((a[i] == 'S' && b[i] == 'T') || (a[i] == 'T' && b[i] == 'S')) { c += 'E'; } else { c += 'S'; } } } if (str.find(c) == str.end()) { return false; } return true; }
#include <bits/stdc++.h> using namespace std; void swap(long long* a, long long* b) { long long temp = *a; *a = *b; *b = temp; } char nxtchr(long long c) { if (c == 1) return '1'; if (c == 2) return '2'; if (c == 3) return '3'; if (c == 4) return '4'; if (c == 5) return '5'; if (c == 6) return '6'; if (c == 7) return '7'; if (c == 8) return '8'; if (c == 9) return '9'; if (c == 0) return '0'; return -1; } int32_t main() { long long n, k, cnt = 0, ans = 0; cin >> n >> k; string s[n], tmp; map<string, vector<long long>> pos; for (long long i = 0; i < n; i++) { cin >> s[i]; pos[s[i]].push_back(i); } for (long long i = 0; i < n; i++) { string s1 = s[i]; for (long long l = i + 1; l < n; l++) { cnt = 0; string s2 = s[l]; tmp = ""; for (long long j = 0; j < k; j++) { if (s1[j] == 'S' && s2[j] == 'S') tmp += "S"; if (s1[j] == 'S' && s2[j] == 'E') tmp += "T"; if (s1[j] == 'S' && s2[j] == 'T') tmp += "E"; if (s1[j] == 'E' && s2[j] == 'E') tmp += "E"; if (s1[j] == 'E' && s2[j] == 'S') tmp += "T"; if (s1[j] == 'E' && s2[j] == 'T') tmp += "S"; if (s1[j] == 'T' && s2[j] == 'T') tmp += "T"; if (s1[j] == 'T' && s2[j] == 'S') tmp += "E"; if (s1[j] == 'T' && s2[j] == 'E') tmp += "S"; } for (long long j = 0; j < pos[tmp].size(); j++) { if (pos[tmp][j] > l) cnt++; } ans += cnt; } } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } long long power(long long x, long long y, long long p = 1000000007) { long long res = 1; x %= p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); long long t = 1; while (t--) { long long n, k; cin >> n >> k; vector<string> v; for (long long i = 0; i < n; i++) { string s; cin >> s; v.push_back(s); } sort((v).begin(), (v).end()); long long ans = 0; for (long long i = 0; i < n; i++) { for (long long j = i + 1; j < n; j++) { string str = ""; for (long long c = 0; c < k; c++) { if (v[i][c] == v[j][c]) { str += v[i][c]; } else { if ((v[i][c] == 'S' && v[j][c] == 'E') || (v[i][c] == 'E' && v[j][c] == 'S')) { str += "T"; } else if ((v[i][c] == 'S' && v[j][c] == 'T') || (v[j][c] == 'S' && v[i][c] == 'T')) { str += "E"; } else { str += "S"; } } } bool found = binary_search(v.begin(), v.end(), str); if (found) { ans++; } } } cout << (ans / 3) << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<ll, ll>; const ll MOD = 1e9 + 7, N = 1e5 + 10; char nn(char a, char b) { if ((a == 'S' and b == 'E') or (b == 'S' and a == 'E')) return 'T'; if ((a == 'S' and b == 'T') or (a == 'T' and b == 'S')) return 'E'; return 'S'; } int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); ll n, k; cin >> n >> k; vector<string> s(n); map<string, ll> cnt; for (ll i = 0; i < n; i++) { cin >> s[i]; cnt[s[i]]++; } string t; ll ans = 0; for (ll i = 0; i < n; i++) { for (ll j = i + 1; j < n; j++) { t = ""; for (ll kk = 0; kk < k; kk++) { if (s[i][kk] == s[j][kk]) { t += s[i][kk]; } else { t += nn(s[i][kk], s[j][kk]); } } ans += cnt[t]; } } cout << ans / 3 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; long long min(long long a, long long b) { if (a > b) return b; return a; } long long max(long long a, long long b) { if (a > b) return a; return b; } int main() { long long t; t = 1; while (t--) { long long n, k; cin >> n >> k; vector<string> v; set<string> second; string g; for (long long i = 0; i < n; i++) { cin >> g; v.push_back(g); second.insert(v[i]); } long long ans = 0; for (long long i = 0; i < n; i++) { for (long long j = i + 1; j < n; j++) { string str = ""; for (long long l = 0; l < k; l++) { if (v[i][l] == 'S' && v[j][l] == 'S') str += 'S'; if (v[i][l] == 'E' && v[j][l] == 'E') str += 'E'; if (v[i][l] == 'T' && v[j][l] == 'T') str += 'T'; if (v[i][l] == 'S' && v[j][l] == 'E') str += 'T'; if (v[i][l] == 'E' && v[j][l] == 'S') str += 'T'; if (v[i][l] == 'T' && v[j][l] == 'S') str += 'E'; if (v[i][l] == 'S' && v[j][l] == 'T') str += 'E'; if (v[i][l] == 'T' && v[j][l] == 'E') str += 'S'; if (v[i][l] == 'E' && v[j][l] == 'T') str += 'S'; } if (second.count(str)) ans++; } } cout << ans / 3 << endl; } }
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int long long n, k; cin >> n >> k; string s[n]; set<string> st; int long long c = 0; for (int long long i = 0; i < n; i++) { cin >> s[i]; st.insert(s[i]); } for (int long long i = 0; i < n; i++) { for (int long long j = i + 1; j < n; j++) { string t = ""; for (int long long p = 0; p < k; p++) { if (s[i][p] == s[j][p]) t += s[i][p]; else { if ((s[i][p] == 'S' && s[j][p] == 'T') || (s[i][p] == 'T' && s[j][p] == 'S')) t += 'E'; else if ((s[i][p] == 'S' && s[j][p] == 'E') || (s[i][p] == 'E' && s[j][p] == 'S')) t += 'T'; else t += 'S'; } } if (st.find(t) != st.end()) { c++; } } } cout << c / 3; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; const int INF = 0x3f3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, k; cin >> n >> k; string arr[n]; set<string> strs; for (int i = 0, ggd = n; i < ggd; i++) { cin >> arr[i]; strs.insert(arr[i]); } ll ans = 0ll; string ss = ""; for (int i = 0, ggd = n - 1; i < ggd; i++) { for (int j = (i + 1), ggd = n; j < ggd; j++) { for (int m = 0, ggd = k; m < ggd; m++) { if (arr[i][m] != arr[j][m]) { ss += ('S' + 'E' + 'T' - arr[i][m] - arr[j][m]); } else ss += arr[i][m]; } if (strs.find(ss) != strs.end()) ans++; ss = ""; } } cout << ans / 3; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; string s[1505]; string t; int main() { int n, k; cin >> n >> k; map<string, int> m; for (int i = 1; i <= n; ++i) cin >> s[i], m[s[i]]++; vector<bool> f(k); while (t.size() < k) t += ' '; ll x = 0; for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { for (int idx = 0; idx <= k - 1; ++idx) { if (s[i][idx] == s[j][idx]) { t[idx] = s[i][idx]; } else { t[idx] = 'S' ^ 'E' ^ 'T' ^ s[i][idx] ^ s[j][idx]; } } if (t == s[i]) x += m[t] - 2; else x += m[t]; } } cout << x / 3 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k, i, j, a; cin >> n >> k; map<string, int> hash; vector<string> arr(n); string s; for (int i = 0; i < n; i++) { cin >> arr[i]; hash[arr[i]]++; } sort(arr.begin(), arr.end()); long long int count = 0; for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { string f = ""; for (a = 0; a < k; a++) { string x; x += arr[i][a]; x += arr[j][a]; if (arr[i][a] == arr[j][a]) f += arr[i][a]; else if (x == "SE" || x == "ES") f += "T"; else if (x == "TE" || x == "ET") f += "S"; else if (x == "ST" || x == "TS") f += "E"; } count += hash[f]; } } cout << count / 3LL; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int count = 0; cin >> n >> k; vector<string> cards; map<string, int> memo; for (int i = 0; i < n; i++) { string card; cin >> card; cards.push_back(card); memo[card] = i; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { string card1 = cards[i]; string card2 = cards[j]; string card3(k, '*'); for (int m = 0; m < k; m++) { char a = card1[m]; char b = card2[m]; char c; if ((a == 'S' && b == 'T') || (a == 'T' && b == 'S')) { c = 'E'; } else if ((a == 'S' && b == 'E') || (a == 'E' && b == 'S')) { c = 'T'; } else if ((a == 'T' && b == 'E') || (a == 'E' && b == 'T')) { c = 'S'; } else { c = a; } card3[m] = c; } if (memo.find(card3) != memo.end() && memo[card3] > j) { count++; } } } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long md = 1e9 + 7; const int N = 1600; const int M = 5100; string ss[N]; map<string, int> mp; string fun(int a, int b, int k) { string sa = ss[a], sb = ss[b]; string ret = sa; for (int i = 0; i < k; i++) { if (sa[i] == sb[i]) ret[i] = sa[i]; else { int s = 1, e = 1, t = 1; if (sa[i] == 'S' || sb[i] == 'S') s = 0; if (sa[i] == 'E' || sb[i] == 'E') e = 0; if (sa[i] == 'T' || sb[i] == 'T') t = 0; if (s == 1) ret[i] = 'S'; if (e == 1) ret[i] = 'E'; if (t == 1) ret[i] = 'T'; } } return ret; } int main() { ios::sync_with_stdio(false); int n, m; int i, j, k; int u, v, w; int a, b, c, d; int z; cin >> n >> k; mp.clear(); for (i = 0; i < n; i++) { cin >> ss[i]; mp[ss[i]] = i; } int num = 0; for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { string a = fun(i, j, k); if (mp.find(a) != mp.end()) { int id = mp[a]; if (id > j) num++; } } } cout << num << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = (0x3f3f3f3f); const int maxn = 1505; unordered_map<string, bool> mp; string s[maxn], t; int n, m; int main() { cin >> n >> m; for (register int(i) = (0); (i) < (n); ++(i)) cin >> s[i], mp[s[i]] = true; int sum = int('S' + 'T' + 'E'); int res = 0; for (register int(i) = (0); (i) < (n); ++(i)) for (register int(j) = (i + 1); (j) < (n); ++(j)) { t.clear(); for (register int(k) = (0); (k) < (m); ++(k)) { if (s[i][k] == s[j][k]) t += s[i][k]; else t += char(sum - int(s[i][k]) - int(s[j][k])); } if (mp[t]) res++; } cout << res / 3 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<string> cards(n); map<string, int> lookup; for (string &card : cards) { cin >> card; if (lookup.find(card) == lookup.end()) { lookup[card] = 1; } else { lookup[card] += 1; } } string possible = "SET"; int ans = 0; for (int i = 0; i + 1 < n; ++i) { for (int j = i + 1; j < n; ++j) { string third; third.resize(k); for (int l = 0; l < k; ++l) { if (cards[i][l] == cards[j][l]) { third[l] = cards[i][l]; } else { for (char c : possible) { if (cards[i][l] != c && cards[j][l] != c) { third[l] = c; } } } } if (lookup.find(third) != lookup.end()) { ans += lookup[third]; } } } cout << ans / 3 << '\n'; }
#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 { if (ff[i] == 'S' and ss[i] == 'E') word += 'T'; else if (ff[i] == 'E' and ss[i] == 'S') word += 'T'; else if (ff[i] == 'E' and ss[i] == 'T') word += 'S'; else if (ff[i] == 'T' and ss[i] == 'E') word += 'S'; else if (ff[i] == 'S' and ss[i] == 'T') word += 'E'; else word += 'E'; } } } 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> using namespace std; struct aaa { aaa() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } aaa; bool ok(char s1, char s2, char s3) { return (s1 == s2 && s2 == s3) || (s1 != s2 && s2 != s3 && s3 != s1); } int main() { int n, k; int ans = 0; cin >> n >> k; vector<string> s(n); map<string, int> u; for (int i = 0; i < n; i++) { cin >> s[i]; u[s[i]] = i + 1; } for (long long i = 0; i < n; i++) { for (long long j = i + 1; j < n; j++) { string si; for (long long l = 0; l < k; l++) { if (s[i][l] == s[j][l]) si += s[i][l]; else si += (char)(((int)'S' + 'E' + 'T') - s[i][l] - s[j][l]); } if (u[si] > j + 1) ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, k; cin >> n >> k; string s[n]; long long ans = 0; for (long long i = 0; i < n; ++i) cin >> s[i]; for (long long i = 0; i < n; ++i) { map<string, long long> avail; for (long long j = i + 1; j < n; ++j) avail[s[j]]++; for (long long j = i + 1; j < n; ++j) { avail[s[j]]--; string req = ""; for (long long h = 0; h < k; ++h) { if (s[i][h] == s[j][h]) req += s[i][h]; else { if ((s[i][h] == 'S' || s[j][h] == 'S') && (s[i][h] == 'E' || s[j][h] == 'E')) req += "T"; else if ((s[i][h] == 'S' || s[j][h] == 'S') && (s[i][h] == 'T' || s[j][h] == 'T')) req += "E"; else req += "S"; } } ans += avail[req]; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; const int LM = 1504; int N, K; string arr[LM]; bool isExist(string tmp, int n1, int n2) { int lo = 1, hi = N, ans = N; while (lo <= hi) { int mid = (lo + hi) / 2; if (arr[mid] >= tmp) hi = mid - 1, ans = mid; else lo = mid + 1; } return (tmp == arr[ans]); } int main() { scanf("%d%d", &N, &K); for (int i = 1; i <= N; i++) { cin >> arr[i]; } sort(arr + 1, arr + N + 1); int ans = 0; for (int i = 1; i <= N; i++) { for (int j = 1; j < i; j++) { string tmp; for (int k = 0; k < K; k++) { if (arr[i][k] == arr[j][k]) tmp.push_back(arr[i][k]); else tmp.push_back('S' + 'E' + 'T' - arr[i][k] - arr[j][k]); } if (tmp == arr[i] || tmp == arr[j]) continue; ans += isExist(tmp, i, j); } } printf("%d\n", ans / 3); return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; string s[1501]; unordered_map<string, bool> m; inline char f(int i, int j, int x) { bool f[3] = {0}; if (s[i][x] == 'S') f[0] = 1; else if (s[i][x] == 'E') f[1] = 1; else f[2] = 1; if (s[j][x] == 'S') f[0] = 1; else if (s[j][x] == 'E') f[1] = 1; else f[2] = 1; if (!f[0]) return 'S'; if (!f[1]) return 'E'; return 'T'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> s[i]; m[s[i]] = 1; } char aux[31]; long long nr = 0; for (int i = 1; i < n; ++i) { for (int j = i + 1; j <= n; ++j) { for (int x = 0; x < k; ++x) { if (s[i][x] == s[j][x]) aux[x] = s[i][x]; else aux[x] = f(i, j, x); } aux[k] = '\0'; if (m[aux] != 0) ++nr; } } return cout << nr / 3, 0; }
#include <bits/stdc++.h> using namespace std; typedef long double ld; const long long INF = 2e9; const long long mod = 1000000007; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, i, k, t, ans = 0, same, j; cin >> n >> k; vector<string> mat(n + 1); set<string> s; string tmp = ""; for (i = 0; i < n; i++) { cin >> mat[i]; s.insert(mat[i]); } for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { tmp = ""; same = 0; for (t = 0; t < k; t++) { if (mat[i][t] == mat[j][t]) tmp += mat[i][t]; else if (mat[i][t] != 'S' && mat[j][t] != 'S') tmp += 'S'; else if (mat[i][t] != 'T' && mat[j][t] != 'T') tmp += 'T'; else if (mat[i][t] != 'E' && mat[j][t] != 'E') tmp += 'E'; } if (s.count(tmp)) ans++; } } cout << ans / 3; return 0; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { return (y ? gcd(y, x % y) : x); } long long lcm(long long x, long long y) { return x * (y / gcd(x, y)); } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, k; cin >> n >> k; vector<string> a(n); set<string> s; for (int i = 0; i < n; i++) { cin >> a[i]; s.insert(a[i]); } long long ans = 0ll; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { string s1 = a[i]; string s2 = a[j]; string aux = ""; for (int z = 0; z < k; z++) { if (s1[z] == s2[z]) aux += s1[z]; else { if (s1[z] != 'T' && s2[z] != 'T') aux += 'T'; if (s1[z] != 'S' && s2[z] != 'S') aux += 'S'; if (s1[z] != 'E' && s2[z] != 'E') aux += 'E'; } } if (s.count(aux)) { ans++; } } } cout << ans / 3 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, K; string s[1501]; set<string> ss; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> K; for (int i = (0); i < (n); ++i) cin >> s[i]; int cnt = 0; ss.insert(s[0]); for (int i = (1); i < (n); ++i) { for (int j = (i + 1); j < (n); ++j) { string t = ""; for (int k = (0); k < (K); ++k) { if (s[i][k] == s[j][k]) t += s[i][k]; else if (s[i][k] != 'S' && s[j][k] != 'S') t += 'S'; else if (s[i][k] != 'E' && s[j][k] != 'E') t += 'E'; else if (s[i][k] != 'T' && s[j][k] != 'T') t += 'T'; } if (ss.count(t)) ++cnt; } ss.insert(s[i]); } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> void read(T &x) { x = 0; register char c = getchar(); register bool f = 0; while (!isdigit(c)) f ^= c == '-', c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); if (f) x = -x; } template <class T> void print(T x) { if (x < 0) putchar('-'), x = -x; if (x > 9) print(x / 10); putchar('0' + x % 10); } void rd() {} const int N = 1509; int T, n, m, ans; unordered_map<string, int> mp; string str[N]; int main() { rd(); scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) cin >> str[i], mp[str[i]] = true; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { string s = ""; for (int k = 0; k < m; k++) { if (str[i][k] == 'S' && str[j][k] == 'S') s += 'S'; else if (str[i][k] == 'T' && str[j][k] == 'T') s += 'T'; else if (str[i][k] == 'E' && str[j][k] == 'E') s += 'E'; else if (str[i][k] == 'S' && str[j][k] == 'T') s += 'E'; else if (str[i][k] == 'T' && str[j][k] == 'S') s += 'E'; else if (str[i][k] == 'E' && str[j][k] == 'T') s += 'S'; else if (str[i][k] == 'T' && str[j][k] == 'E') s += 'S'; else if (str[i][k] == 'S' && str[j][k] == 'E') s += 'T'; else if (str[i][k] == 'E' && str[j][k] == 'S') s += 'T'; } if (mp[s]) ans++; } } printf("%d\n", ans / 3); return 0; }
#include <bits/stdc++.h> using namespace std; long long mo(const long long input, const long long ceil) { return input >= ceil ? input % ceil : input; } void solve(long long tt) { string str[1600]; map<string, long long> mp; long long n, k, num = 0; cin >> n >> k; for (long long i = 0; i < n; i++) { cin >> str[i]; mp[str[i]]++; } for (long long i = 0; i < n; i++) { for (long long j = i + 1; j < n; j++) { string temp = ""; for (long long l = 0; l < k; l++) { if (str[i][l] == str[j][l]) temp += str[i][l]; else temp += 'S' + 'E' + 'T' - str[i][l] - str[j][l]; } if (mp.count(temp)) num++; } } cout << num / 3 << endl; } signed main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long tt = 1; for (long long i = 0; i < tt; i++) solve(tt); cerr << "Time : " << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC << "ms\n"; ; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n; cin >> k; vector<string> s(n); set<string> exist; for (int i = 0; i < n; i++) { cin >> s[i]; exist.insert(s[i]); } long long int count = 0; for (int x = 0; x < n - 1; x++) { for (int y = x + 1; y < n; y++) { string temp = ""; for (int i = 0; i < k; i++) { if (s[x][i] == s[y][i]) { temp += s[x][i]; } else if ((s[x][i] == 'S' && s[y][i] == 'T') || (s[x][i] == 'T' && s[y][i] == 'S')) { temp += 'E'; } else if ((s[x][i] == 'S' && s[y][i] == 'E') || (s[x][i] == 'E' && s[y][i] == 'S')) { temp += 'T'; } else if ((s[x][i] == 'E' && s[y][i] == 'T') || (s[x][i] == 'T' && s[y][i] == 'E')) { temp += 'S'; } } if (exist.find(temp) != exist.end()) { count++; } } } cout << count / 3 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; inline int read() { int ans = 0; bool f = 1; char ch = getchar(); while (!isdigit(ch)) f ^= ch == '-', ch = getchar(); while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = getchar(); return f ? ans : -ans; } int n, k; set<string> st; int ans; int main(int argc, char const *argv[]) { ios::sync_with_stdio(false); cin >> n >> k; while (n--) { string s; cin >> s; for (auto it : st) { for (int j = k; j--;) if (it[j] ^ s[j]) it[j] ^= 66 ^ s[j]; ans += st.count(it); } st.insert(s); } cout << ans / 2; 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; int main() { 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(k, '0'); for (int k = (0); k < (s[i].size()); ++k) if (s[i][k] == s[j][k]) tmp[k] = s[i][k]; else tmp[k] = 'S' ^ 'E' ^ 'T' ^ s[i][k] ^ s[j][k]; ans += UM[tmp]; } } cout << ans / 3; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool uax(T &x, T y) { return (y > x) ? x = y, true : false; } template <typename T> inline bool uin(T &x, T y) { return (y < x) ? x = y, true : false; } string to_string(char c) { return "'" + string(1, c) + "'"; } string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } template <typename A> string to_string(A); template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ": " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool f = false; string r = "{"; for (auto x : v) { if (f) r += ", "; r += to_string(x); f = true; } return r += "}"; } template <typename A> string to_string(vector<vector<A>> v) { string r; for (auto x : v) r += "\n" + to_string(x); return r; } int Nerr; template <typename A> string to_string(A *p) { return to_string(vector<A>(p, p + Nerr)); } void err(istream_iterator<string>) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); } template <typename T> void kek(T ans) { cout << ans << endl; exit(0); } int const MOD = 1e9 + 7; long long const INF = 1e18 + 42; int32_t main() { cin.tie(nullptr)->sync_with_stdio(false); int n, k; cin >> n >> k; map<long long, int> cnt; vector<long long> a(n); for (int i = 0; i < n; ++i) { string s; cin >> s; long long cur = 0; for (int j = 0; j < k; ++j) { cur *= 3; if (s[j] == 'S') cur += 0; if (s[j] == 'E') cur += 1; if (s[j] == 'T') cur += 2; } a[i] = cur; cnt[cur]++; } int ans = 0; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { long long x = a[i], y = a[j]; vector<int> b(k); for (int p = 0; p < k; ++p) { if (x % 3 == y % 3) { b[p] = x % 3; } else { b[p] = 3 - x % 3 - y % 3; } x /= 3; y /= 3; } long long cur = 0; for (int p = k - 1; p >= 0; --p) { cur *= 3; cur += b[p]; } ans += cnt[cur]; ans -= a[i] == cur; ans -= a[j] == cur; } } kek(ans / 3); }
#include <bits/stdc++.h> #pragma GCC optimize("O3") const long long MOD = 1e9 + 7; using namespace std; long long n_bits(long long n) { long long x = __builtin_popcount(n); return x; } char get(char x, char y) { if ((x == 'S' and y == 'E') or (x == 'E' and y == 'S')) return 'T'; if ((x == 'S' and y == 'T') or (x == 'T' and y == 'S')) return 'E'; return 'S'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); map<string, long long> m; long long n, k, count = 0; cin >> n >> k; string v[n]; for (int i = 0; i < (n); ++i) { cin >> v[i]; } 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 += v[i][l]; } else { s += get(v[i][l], v[j][l]); } } count += m[s]; } m[v[i]]++; } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int T, N; long long X, M; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> T; int sol; long long a; while (T--) { cin >> N >> X; M = 0; for (int i = 0; i < N; i++) { cin >> a; if (M == X) continue; M = max(a, M); if (a == X) M = X; } long long sol = X / M; if (M == X) sol = 1; else { if (X % M) sol++; sol = max(sol, 2LL); } cout << sol << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long gcd(long long x, long long y) { if (!y) return x; return gcd(y, x % y); } long long inv(long long x) { long long r = 1ll, t = x, k = MOD - 2ll; while (k) { if (k & 1ll) r = (long long)r * t % MOD; t = (long long)t * t % MOD; k >>= 1; } return r; } void min_self(int &a, int b) { a = min(a, b); } int n, x; vector<int> a; void readIN() { cin >> n >> x; a.resize(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); for (int i = 0; i < n; i++) if (a[i] == x) { cout << 1 << endl; return; } cout << max(2, (x + a[n - 1] - 1) / a[n - 1]) << endl; } void solve() {} int main() { ios_base::sync_with_stdio(false); cin.tie(); int t; cin >> t; while (t--) { readIN(); solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; int n, x; int favourites[maxn]; void solve() { cin >> n >> x; bool found = false; int maxval = 0; for (int i = 1; i <= n; i++) { cin >> favourites[i]; if (favourites[i] == x) found = true; maxval = max(maxval, favourites[i]); } if (found) { cout << "1\n"; return; } if (maxval * 2 >= x) { cout << "2\n"; return; } int result = ((x - 2 * maxval) + (maxval - 1)) / maxval; result += 2; cout << result << "\n"; return; } int main() { int T; cin >> T; while (T--) { solve(); } }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; int main() { int t; cin >> t; while (t--) { int n, x; cin >> n >> x; int ans = 0x3f3f3f3f, m, a; m = x / 2 + x % 2; for (int i = 1; i <= n; i++) { cin >> a; if (a == x) ans = 1; if (a >= m) ans = min(ans, 2); if (a < m) { if (x % a) ans = min(ans, x / a + 1); else ans = min(ans, x / a); } } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, x; cin >> n >> x; long long int closest = 99999999; long long int aux; long long int mxnum = 0; bool flag = true; for (long long int i(0); i < n; i++) { cin >> aux; mxnum = max(mxnum, aux); if (aux == x) { cout << 1 << endl; flag = false; } } if (flag) { if (x > mxnum) { cout << (x + mxnum - 1) / mxnum << endl; } else { cout << 2 << endl; } } } return 0; }
#include <bits/stdc++.h> using namespace std; ifstream fin("test.in"); int main() { ios::sync_with_stdio(false); int t, i, n, d, maxim, x; cin >> t; while (t--) { cin >> n >> d; maxim = -1; for (i = 1; i <= n; i++) { cin >> x; if (x == d || maxim == d) maxim = d; else maxim = max(x, maxim); } if (d < maxim) cout << 2 << '\n'; else if (d % maxim) cout << d / maxim + 1 << '\n'; else cout << d / maxim << '\n'; } }
#include <bits/stdc++.h> using namespace std; mt19937_64 rang( chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int lim) { uniform_int_distribution<int> uid(0, lim - 1); return uid(rang); } int mpow(int base, int exp); void ipgraph(int n, int m); void dfs(int u, int par); const int mod = 1e9 + 7; const int N = 3e5, M = N; vector<int> g[N]; int a[N]; void solve() { long long n, m; cin >> n >> m; vector<long long> arr(n); bool f = false; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] == m) f = true; } if (f) { cout << 1 << endl; return; } sort(arr.rbegin(), arr.rend()); int x = m / arr[0]; if (m % arr[0] != 0) x++; cout << max(2, x) << endl; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); int t = 1; cin >> t; while (t--) { solve(); } return 0; } int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((long long)result * base) % mod; base = ((long long)base * base) % mod; exp >>= 1; } return result; } void ipgraph(int n, int m) { int i, u, v; while (m--) { cin >> u >> v; u--, v--; g[u].push_back(v); g[v].push_back(u); } } void dfs(int u, int par) { for (int v : g[u]) { if (v == par) continue; dfs(v, u); } }
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, i, maxi, ans, p, x; cin >> t; while (t--) { cin >> n >> x; maxi = 0; ans = 0; for (i = 0; i < n; i++) { cin >> p; if (x == p) ans = 1; maxi = max(maxi, p); } if (ans != 0) { cout << ans << endl; continue; } if (x < 2 * maxi) { cout << 2 << endl; continue; } ans = (x - 2 * maxi) / maxi; if ((x - 2 * maxi) % maxi != 0) ans += 1; ans += 2; cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t-- > 0) { int n; cin >> n; int x; cin >> x; int maxi = INT_MIN; set<int> q; int i; for (i = 0; i < n; i++) { int r; cin >> r; q.insert(r); if (r > maxi) maxi = r; } if (q.find(x) != q.end()) cout << "1" << endl; else cout << max(2, x % maxi == 0 ? x / maxi : (x / maxi) + 1) << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int T; cin >> T; while (T--) { long long n, b; cin >> n >> b; bool flag = false; long long Max = 0; for (int i = 0; i < n; i++) { long long x; cin >> x; Max = max(Max, x); if (x == b) flag = true; } if (flag) cout << 1 << "\n"; else { if (Max < b) cout << long(ceil(b / double(Max))) << "\n"; else cout << 2 << "\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long i, j, k, m, n, p, s, t, x, a[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); for (cin >> t; t--;) { cin >> n >> x; for (i = p = 0; i < n; i++) { cin >> a[i]; if (a[i] == x) p = 1; } sort(a, a + n); if (p) cout << 1 << endl; else if (a[n - 1] > x) cout << 2 << endl; else cout << (x - 1) / a[n - 1] + 1 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, t, i, maxx, c, x; cin >> t; bool flag; for (; t > 0; t--) { cin >> n >> x; maxx = 0; flag = false; for (i = 1; i <= n; i++) { cin >> c; if (c == x) flag = true; else maxx = max(maxx, c); } if (flag) cout << 1 << endl; else { if (maxx > x) cout << 2 << endl; else { if (x % maxx == 0) cout << x / maxx << endl; else cout << x / maxx + 1 << endl; } } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i, j, k, l, x, y, t; cin >> t; while (t--) { cin >> n >> x; set<long long int> s; long long int mx = 0; for (i = 0; i < n; i++) { cin >> k; s.insert(k); mx = max(mx, k); } if (s.count(x)) cout << 1 << endl; else cout << max(2LL, (x + mx - 1) / mx) << endl; } }
#include <bits/stdc++.h> using namespace std; void solve() { int n; long long int x; cin >> n >> x; int i = 0; long long int maxi = LONG_LONG_MIN; bool found = false; for (i = 0; i < n; i++) { long long int temp; cin >> temp; if (temp > maxi) maxi = temp; if (temp == x) found = true; } if (found) cout << "1" << endl; else cout << max(2LL, (long long int)ceil(((double)x) / maxi)) << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc; cin >> tc; for (int t = 1; t <= tc; t++) { solve(); } }
#include <bits/stdc++.h> using namespace std; int t, n, k, x, maxnum; int main() { cin >> t; while (t--) { maxnum = -1000; bool flag = false; cin >> n >> x; for (int i = 0; i < n; i++) { cin >> k; if (k == x) flag = true; maxnum = max(maxnum, k); } if (flag) cout << 1 << endl; else cout << max(2, (maxnum + x - 1) / maxnum) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int t; int a[100005]; int main() { cin >> t; while (t--) { int n, d; cin >> n >> d; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); if (d < a[n - 1]) { int k = lower_bound(a, a + n, d) - a; if (a[k] == d) cout << 1 << endl; else cout << 2 << endl; } else cout << (d - 1) / (a[n - 1]) + 1 << endl; } }
#include <bits/stdc++.h> using namespace std; void solve() { long long n, x, i, c = 0, f = 0, d = 2; cin >> n >> x; long long a[n]; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] == x) f = 1; c = max(c, a[i]); } if (f == 1) { cout << "1" << endl; return; } if (x % c == 0) { c = x / c; c = max(c, d); cout << c << endl; return; } c = (x / c) + 1; c = max(c, d); cout << c << endl; return; } int main() { int t; cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long int n, x; cin >> n >> x; long int arr[n], result, c = 0; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n, greater<int>()); for (int i = 0; i < n; i++) { if (arr[i] == x) { c = 1; break; } } if (c == 1) cout << "1" << endl; else { int res = ceil((x * 1.0) / arr[0]); cout << max(2, res) << endl; } } }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int tt, qq = 0; cin >> tt; while (tt--) { int n; long long x; cin >> n >> x; vector<long long> A(n); for (int i = 0; i < n; i++) { cin >> A[i]; } sort(A.begin(), A.end()); long long mx = A.back(); auto u = binary_search(A.begin(), A.end(), x); if (u) { cout << 1 << '\n'; continue; } long long ans = x / mx; if (x % mx != 0) { if (!ans) ans++; ans++; } cout << ans << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, d; cin >> n >> d; long long int ar[n]; for (int i = 0; i < n; i++) cin >> ar[i]; sort(ar, ar + n); bool flag = false; for (int i = n - 1; i >= 0; i--) { if (ar[i] == d) { cout << 1 << endl; flag = true; break; } } long long int temp = ar[n - 1]; if (!flag) { if (d % temp == 0) cout << d / temp << endl; else cout << max(d / temp + 1, 2LL) << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = (int)(1e9 + 7); const double EPS = 1e-6; int n, t, d, a[500000]; int main() { cin >> t; int x; for (int ttt = 1; ttt <= t; ttt++) { cin >> n >> x; bool was = false; int maxx = -100; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] >= maxx) maxx = a[i]; if (a[i] == x) was = true; } if (was == true) cout << 1 << "\n"; else if (maxx > x) { cout << 2 << "\n"; } else cout << (x + maxx - 1) / maxx << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed; srand(time(0)); int t; cin >> t; while (t--) { int n, d; cin >> n >> d; set<int> s; for (int i = 0; i < n; i++) { int a; cin >> a; s.insert(a); } int ans = 2e9; for (auto x : s) { if (x > d) { ans = min(ans, 2); } else if (d % x == 0) { ans = min(ans, d / x); } else { int a = d % x; int b = d / x; if (s.find(a) != s.end() || d - b * x <= x) { ans = min(ans, b + 1); } else { ans = min(ans, b + 2); } } } cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, inf = 1061109567; const long long infll = 4557430888798830399; const int N = 1e5 + 5; int n, a[N], x; int ceiling(int a, int b) { return (a + b - 1) / b; } void proc() { cin >> n >> x; for (int i = 0; i < n; i++) cin >> a[i]; int ans = inf; for (int i = 0; i < n; i++) { if (a[i] == x) { cout << "1\n"; return; } ans = min(ans, max(2, ceiling(x, a[i]))); } cout << ans << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) proc(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, x, i, f = 0; cin >> n >> x; long long int arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); for (i = 0; i < n; i++) { if (x == arr[i]) { cout << 1 << endl; f = 1; break; } } if (f == 1) continue; if (x / 2 < arr[n - 1]) { cout << 2 << endl; continue; } else { if (x % arr[n - 1] == 0) { cout << x / arr[n - 1] << endl; continue; } else { cout << x / arr[n - 1] + 1 << endl; continue; } } } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, d, flag = 0, flag1 = 0, m = 0; cin >> n >> d; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == d) flag = 1; if (a[i] > m) m = a[i]; } flag1 = d / m; if (flag1 * m != d) flag1++; if (flag1 == 1) flag1 = 2; if (flag == 1) cout << 1 << endl; else cout << flag1 << endl; } }
#include <bits/stdc++.h> using namespace std; long long n, d; map<long long, bool> mp; int main() { int t; cin >> t; while (t--) { cin >> n >> d; long long mx = -1000000000000000000; mp.clear(); for (int i = 0; i < n; i++) { long long a; cin >> a; mx = max(mx, a); mp[a] = 1; } int ans = (d - 1) / mx + 1; ans += (ans == 1 && !mp[d]); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) { return b; } if (b == 0) { return a; } return gcd(b, a % b); } long long power_mod(long long a, long long b) { if (b == 0) { return 1; } long long temp = power_mod(a, b / 2); temp = (temp * temp) % 1000000007; if (b % 2) { temp = (temp * a) % 1000000007; } return temp; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; cin >> t; while (t--) { long long n, x; cin >> n >> x; set<long long> s; for (int i = 0; i < n; ++i) { long long a; cin >> a; s.insert(a); } long long ans; if (s.find(x) != s.end()) { ans = 1; } else { long long maxi = *s.rbegin(); long long temp = ceil(x / (maxi * 1.0)); if (temp == x / maxi) { ans = temp; } else { ans = max(2ll, temp); } } cout << ans << "\n"; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, x; cin >> n >> x; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); if (find(a.begin(), a.end(), x) != a.end()) cout << "1\n"; else { int m = *max_element(a.begin(), a.end()); int k = ceil((double)x / m); if (k >= 2) cout << k << "\n"; else cout << 2 << "\n"; } } }
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; } void solve() { int t; cin >> t; while (t--) { long long n, x; cin >> n >> x; int i; long long mm = 0; bool flag = false; long long c; for (i = 0; i < n; i++) { cin >> c; mm = max(mm, c); if (c == x) { cout << (1) << endl; flag = true; } } if (!flag) cout << max((long long)2, (x + mm - 1) / mm) << endl; } }
#include <bits/stdc++.h> using namespace std; signed main() { long long t = 1; cin >> t; while (t--) { long long n, k, mini, i, x; cin >> n >> k; mini = LLONG_MAX; for (i = 0; i < n; i++) { cin >> x; mini = min(mini, k / x + (k / x == 0) + (k % x != 0)); } cout << mini << "\n"; } return 0; }