Submission #232519

# Submission time Handle Problem Language Result Execution time Memory
232519 2020-05-17T09:31:22 Z VEGAnn Parametriziran (COCI19_parametriziran) C++14
110 / 110
489 ms 39088 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ft first
#define sd second
#define sz(x) ((int)x.size())
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
const int N = 50100;
const ll Z = 28;
gp_hash_table<int, int> mem;
string s[N];
int n, m;
ll ans = 0;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> m;

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

        for (int msk = 0; msk < (1 << m); msk++){
            bool bad = 0;
            int t = 0;

            for (int j = 0; j < m && !bad; j++)
                if (msk & (1 << j)) {
                    if (s[i][j] == '?')
                        bad = 1;
                    else t = t * Z + 26;
                } else {
                    if (s[i][j] == '?')
                        t = t * Z + 27;
                    else t = t * Z + (s[i][j] - 'a');
                }

            if (!bad)
                mem[t]++;
        }
    }

    for (int i = 0; i < n; i++){
        for (int msk = 0; msk < (1 << m); msk++){
            int t = 0;

            for (int j = 0; j < m; j++)
                if (msk & (1 << j)) {
                    if (s[i][j] == '?')
                        t = t * Z + 26;
                    else t = t * Z + 27;
                } else {
                    if (s[i][j] == '?')
                        t = t * Z + 27;
                    else t = t * Z + (s[i][j] - 'a');
                }

            if (mem.find(t) != mem.end())
                ans += mem[t];
        }
    }

    cout << (ans - n) / 2;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1920 KB Output is correct
2 Correct 9 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1920 KB Output is correct
2 Correct 12 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2624 KB Output is correct
2 Correct 26 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2624 KB Output is correct
2 Correct 86 ms 3196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 355 ms 6636 KB Output is correct
2 Correct 35 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 11376 KB Output is correct
2 Correct 34 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 170 ms 20568 KB Output is correct
2 Correct 104 ms 11368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 340 ms 38984 KB Output is correct
2 Correct 94 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 489 ms 39088 KB Output is correct
2 Correct 412 ms 20572 KB Output is correct