답안 #232504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
232504 2020-05-17T08:49:37 Z VEGAnn Parametriziran (COCI19_parametriziran) C++14
0 / 110
234 ms 37496 KB
#include <bits/stdc++.h>
#define ft first
#define sd second
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 50100;
const int Z = 28;
string s[N], t;
int n, m;
ll ans = 0;

struct trie{
    trie* next[Z];
    int kol;

    trie(): kol(0) {
        fill(next, next + Z, nullptr);
    }

    void insert(string &cur, int id){
        kol++;

        if (id == m) return;

        int ch = 0;

        if (cur[id] == '#')
            ch = 26;
        else if (cur[id] == '?')
            ch = 27;
        else ch = (cur[id] - 'a');

//        cerr << next[ch] << '\n';

        if (!next[ch])
            next[ch] = new trie();

        next[ch] -> insert(cur, id + 1);
    }

    void calc(string &cur, int id){
        if (id == m){
            ans += kol;
            return;
        }

        if (cur[id] == '?'){
            if (next[26]) next[26] -> calc(cur, id + 1);
            next[27] -> calc(cur, id + 1);
        } else next[cur[id] - 'a'] -> calc(cur, id + 1);
    }
};

trie* root;

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

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

    cin >> n >> m;

    root = new trie();

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

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

            for (int j = 0; j < m && !bad; j++)
                if (msk & (1 << j)) {
                    if (s[i][j] == '?')
                        bad = 1;
                    else t += "#";
                } else t += s[i][j];

            if (!bad)
                root -> insert(t, 0);
        }
    }

    for (int i = 0; i < n; i++)
        root -> calc(s[i], 0);

    cout << (ans - n) / 2;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 1920 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 2048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 2048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 4096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 15864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 76 ms 17656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 114 ms 24696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 175 ms 23288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 234 ms 37496 KB Output isn't correct
2 Halted 0 ms 0 KB -