Submission #444471

#TimeUsernameProblemLanguageResultExecution timeMemory
444471zxcvbnmParametriziran (COCI19_parametriziran)C++14
0 / 110
3080 ms1356 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int p = 31; const int mod = 1e9 + 9; ll hsh(const string& s) { ll ret = 0; ll p_pow = 1; for(char c : s) { int ch = 26; if (isalpha(c)) { ch = c - 'a'; } else if (c == '*') { ch = 27; } // cout << c << " " << ch << "\n"; ret = (ret + ch * p_pow) % mod; p_pow = (p_pow * p) % mod; } return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); freopen("failas.in", "r", stdin); int n, m; cin >> n >> m; map<int, int> cnt; vector<string> a(n); for(int i = 0; i < n; i++) { string str; cin >> str; a[i] = str; } for(int i = 0; i < n; i++) { for(int mask = 0; mask < (1 << m); mask++) { string s = a[i]; for(int j = 0; j < m; j++) { if (mask & (1 << j)) { s[j] = '*'; } } // cout << s << " " << hsh(s) << "\n"; cnt[hsh(s)]++; } } ll ans = 0; for(string str : a) { vector<int> idx; for(int i = 0; i < m; i++) { if (isalpha(str[i])) { idx.push_back(i); } } int letters = idx.size(); string str2 = str; for(char& c : str2) { if (c == '?') { c = '*'; } } for(int mask = 0; mask < (1 << letters); mask++) { string s = str2; for(int j = 0; j < letters; j++) { if (mask & (1 << j)) { s[idx[j]] = '?'; } } // cout << s << " "; // cout << cnt[s] << "\n"; ans += cnt[hsh(s)]; } // cerr << "\n"; } ans -= n; ans /= 2; cout << ans << "\n"; return 0; }

Compilation message (stderr)

parametriziran.cpp: In function 'int main()':
parametriziran.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen("failas.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...