Submission #867382

# Submission time Handle Problem Language Result Execution time Memory
867382 2023-10-28T09:59:57 Z Vladth11 Lozinke (COCI17_lozinke) C++14
85 / 100
29 ms 35124 KB
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast")
 
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
 
const ll NMAX = 150002;
const ll INF = (1LL << 60);
const ll nrbits = 20;
const ll MOD = 998244353;
const ll bucket = 320;
const double eps = 0.00000001;
 
int trie[NMAX][26];
int last[NMAX];
int nr[NMAX];
int subsecv[NMAX];
int cnt = 0;
int root;
ll sol;
string s;
int acum;
 
void baga(int node, int idx, int full) {
    if(last[node] != acum) {
        sol += nr[node];
        subsecv[node]++;
    }
    last[node] = acum;
    if(idx == s.size()) {
        nr[node] += full;
        if(full){
            sol += (subsecv[node] - 1);
        }
        return;
    }
 
    if(node == root) {
        for(int i = 0; i < s.size(); i++) {
            int nxt = s[i] - 'a';
            if(trie[node][nxt] == 0) {
                trie[node][nxt] = ++cnt;
            }
            baga(trie[node][nxt], i + 1, (i == 0));
        }
        return;
    }
    int nxt = s[idx] - 'a';
    if(trie[node][nxt] == 0) {
        trie[node][nxt] = ++cnt;
    }
    baga(trie[node][nxt], idx + 1, full);
}
 
signed main() {
#ifdef HOME
    ifstream cin(".in");
    ofstream cout(".out");
#endif // HOME
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, i;
    root = ++cnt;
    cin >> n;
    for(i = 1; i <= n; i++) {
        cin >> s;
        acum = i;
        baga(root, 0, 1);
    }
    cout << sol;
    return 0;
}

Compilation message

lozinke.cpp: In function 'void baga(int, int, int)':
lozinke.cpp:33:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     if(idx == s.size()) {
      |        ~~~~^~~~~~~~~~~
lozinke.cpp:42:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for(int i = 0; i < s.size(); i++) {
      |                        ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 2 ms 3164 KB Output is correct
9 Correct 3 ms 2908 KB Output is correct
10 Correct 9 ms 10332 KB Output is correct
11 Correct 5 ms 5468 KB Output is correct
12 Runtime error 27 ms 35124 KB Execution killed with signal 11
13 Correct 11 ms 2904 KB Output is correct
14 Runtime error 26 ms 34904 KB Execution killed with signal 11
15 Runtime error 29 ms 34896 KB Execution killed with signal 11
16 Correct 7 ms 600 KB Output is correct
17 Correct 5 ms 348 KB Output is correct
18 Correct 4 ms 484 KB Output is correct
19 Correct 15 ms 11284 KB Output is correct
20 Correct 4 ms 672 KB Output is correct