Submission #97585

# Submission time Handle Problem Language Result Execution time Memory
97585 2019-02-17T10:10:53 Z szawinis Parametriziran (COCI19_parametriziran) C++17
110 / 110
2631 ms 43160 KB
#include <bits/stdc++.h>
#define long long long
using namespace std;

int n, m;
long ans;
map<int, int> ls[64][64];
void solve(istream& cin) {
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        int h = 0, mask1 = 0;
        for(int j = 0; j < m; j++) if(s[j] != '?') mask1 |= 1 << j;
        int tmp[64];
        fill(tmp, tmp+64, -1);
        for(int mask2 = 0; mask2 < 1 << m; mask2++) if((mask2 & mask1) == mask2) {
                int h = 0;
                for(int j = 0, p = 1; j < m; j++, p *= 26) {
                    if(mask2 >> j & 1) {
                        h += p * (s[j] - 'a');
                    }
                }
                tmp[mask2] = h;
            }
        // different mask2
        for(int mask2 = 0; mask2 < 1 << m; mask2++) {
            int and_mask = mask1 & mask2;
            int h = tmp[and_mask];
            if(ls[mask2][and_mask].count(h))
                ans += ls[mask2][and_mask][h];
        }
        for(int mask2 = 0; mask2 < 1 << m; mask2++) if(tmp[mask2] >= 0) ++ls[mask1][mask2][tmp[mask2]];
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
//    ifstream in("1.in");
    solve(cin);
}

Compilation message

parametriziran.cpp: In function 'void solve(std::istream&)':
parametriziran.cpp:13:13: warning: unused variable 'h' [-Wunused-variable]
         int h = 0, mask1 = 0;
             ^
# Verdict Execution time Memory Grader output
1 Correct 11 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 640 KB Output is correct
2 Correct 11 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 640 KB Output is correct
2 Correct 26 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 1252 KB Output is correct
2 Correct 28 ms 880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 1244 KB Output is correct
2 Correct 57 ms 1640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 382 ms 5752 KB Output is correct
2 Correct 31 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 593 ms 10008 KB Output is correct
2 Correct 36 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1031 ms 18232 KB Output is correct
2 Correct 432 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1411 ms 28624 KB Output is correct
2 Correct 69 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2631 ms 43160 KB Output is correct
2 Correct 1377 ms 21564 KB Output is correct