QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#666435#5311. Master of BothtselmegkhCompile Error//C++141.5kb2024-10-22 18:28:052024-10-22 18:28:13

Judging History

你现在查看的是最新测评结果

  • [2024-10-22 18:28:13]
  • 评测
  • [2024-10-22 18:28:05]
  • 提交

answer

#include<iostream>
using namespace std;

const int N = 1e5 + 5;
const int K = 26;

struct Vertex {
    int next[K];
    int lst = 0;

    Vertex() {
        fill(begin(next), end(next), -1);
    }
};

vector<Vertex> t(1);
int cnt[K][K];
long long ans;

void add_string(string const& s){
    int v = 0;
    bool isPrefix = true;
    for(char ch : s){
        int c = ch - 'a';
        for(int j = 0; j < 26; j++){
            if(t[v].next[j] != -1){
                cnt[j][c] += t[t[v].next[j]].lst;
            }
        }
        if(t[v].next[c] == -1){
            isPrefix = false;
            t[v].next[c] = t.size();
            t.emplace_back();
        }
        t[v].lst++;
        v = t[v].next[c];
    }
    ans += t[v].lst;
    t[v].lst++;
}

void solve(){
    int n, q;
    cin >> n >> q;

    vector<string> s(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
        add_string(s[i]);
    }
    while(q--){
        string alphabet;
        cin >> alphabet;
        vector<int> pos(26, 0);

        for(int j = 0; j < 26; j++){
            pos[alphabet[j] - 'a'] = j;
        }
        long long res = 0;
        for(int i = 0; i < 26; i++){
            for(int j = 0; j < 26; j++){
                if(i == j)continue;
                if(pos[i] < pos[j]){
                    res += cnt[j][i];
                }
            }
        }
        cout << res + ans << '\n';
    }
    
}

int main() {
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }        
}

Details

answer.code:16:1: error: ‘vector’ does not name a type
   16 | vector<Vertex> t(1);
      | ^~~~~~
answer.code: In function ‘void add_string(const std::string&)’:
answer.code:26:16: error: ‘t’ was not declared in this scope
   26 |             if(t[v].next[j] != -1){
      |                ^
answer.code:30:12: error: ‘t’ was not declared in this scope
   30 |         if(t[v].next[c] == -1){
      |            ^
answer.code:35:9: error: ‘t’ was not declared in this scope
   35 |         t[v].lst++;
      |         ^
answer.code:38:12: error: ‘t’ was not declared in this scope
   38 |     ans += t[v].lst;
      |            ^
answer.code: In function ‘void solve()’:
answer.code:46:5: error: ‘vector’ was not declared in this scope
   46 |     vector<string> s(n);
      |     ^~~~~~
answer.code:2:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    1 | #include<iostream>
  +++ |+#include <vector>
    2 | using namespace std;
answer.code:46:18: error: expected primary-expression before ‘>’ token
   46 |     vector<string> s(n);
      |                  ^
answer.code:46:20: error: ‘s’ was not declared in this scope
   46 |     vector<string> s(n);
      |                    ^
answer.code:54:16: error: expected primary-expression before ‘int’
   54 |         vector<int> pos(26, 0);
      |                ^~~
answer.code:57:13: error: ‘pos’ was not declared in this scope
   57 |             pos[alphabet[j] - 'a'] = j;
      |             ^~~
answer.code:63:20: error: ‘pos’ was not declared in this scope
   63 |                 if(pos[i] < pos[j]){
      |                    ^~~