Submission #444467

# Submission time Handle Problem Language Result Execution time Memory
444467 2021-07-14T06:53:40 Z zxcvbnm Parametriziran (COCI19_parametriziran) C++14
88 / 110
1510 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    map<string, int> cnt;
    vector<string> a(n);

    for(int i = 0; i < n; i++) {
        string str;
        cin >> str;
        a[i] = str;

        for(int mask = 0; mask < (1 << m); mask++) {
            string s = str;
            for(int j = 0; j < m; j++) {
                if (mask & (1 << j)) {
                    s[j] = '*';
                }
            }
            cnt[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[s];
        }
//        cerr << "\n";
    }

    ans -= n;
    ans /= 2;
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1356 KB Output is correct
2 Correct 27 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 1748 KB Output is correct
2 Correct 53 ms 1996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 2480 KB Output is correct
2 Correct 58 ms 1744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 2872 KB Output is correct
2 Correct 119 ms 3652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 543 ms 13508 KB Output is correct
2 Correct 149 ms 2756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 910 ms 30640 KB Output is correct
2 Correct 228 ms 3652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1510 ms 56540 KB Output is correct
2 Correct 822 ms 26564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1453 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1200 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -