답안 #444471

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444471 2021-07-14T07:10:38 Z zxcvbnm Parametriziran (COCI19_parametriziran) C++14
0 / 110
3000 ms 1356 KB
#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

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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3074 ms 1356 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3078 ms 1356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3046 ms 1356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3080 ms 1356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3058 ms 1356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3075 ms 1356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3046 ms 1356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3066 ms 1356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3072 ms 1356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3036 ms 1356 KB Time limit exceeded
2 Halted 0 ms 0 KB -