제출 #1339491

#제출 시각아이디문제언어결과실행 시간메모리
1339491po_rag526Parametriziran (COCI19_parametriziran)C++20
110 / 110
1016 ms4252 KiB
#include <bits/stdc++.h>
#pragma GCC optimization("Ofast,unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC target("avx2,popcnt")
using namespace std;

unordered_map<string, int> fr;

string s[50005];
vector<int> id[64];

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, m, ans = 0;
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> s[i];
        int mask = 0;
        for(int j = 0; j < m; j++){
            if(s[i][j] != '?'){
                mask ^= (1 << j);
            }
        }
        id[mask].push_back(i);
    }
    for(int mask1 = 0; mask1 < 1 << m; mask1++){
        for(int mask2 = 0; mask2 < 1 << m; mask2++){
            int comun = mask1 & mask2;
            map<string, int> fr;
            for(int i : id[mask1]){
                string here = "";
                for(int j = 0; j < m; j++){
                    if(comun & (1 << j))
                        here += s[i][j];
                }
                fr[here]++;
            }
            for(int i : id[mask2]){
                string here = "";
                for(int j = 0; j < m; j++){
                    if(comun & (1 << j))
                        here += s[i][j];
                }
                ans += fr[here];
            }
        }
    }
    cout << (ans - n) / 2 << '\n';

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...