Submission #867384

# Submission time Handle Problem Language Result Execution time Memory
867384 2023-10-28T10:01:17 Z Vladth11 Lozinke (COCI17_lozinke) C++14
90 / 100
33 ms 41276 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 = 180002;
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];
short 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 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 3160 KB Output is correct
9 Correct 4 ms 3160 KB Output is correct
10 Correct 7 ms 10072 KB Output is correct
11 Correct 5 ms 5212 KB Output is correct
12 Runtime error 30 ms 41276 KB Execution killed with signal 11
13 Correct 7 ms 2904 KB Output is correct
14 Correct 13 ms 20316 KB Output is correct
15 Runtime error 33 ms 41248 KB Execution killed with signal 11
16 Correct 6 ms 668 KB Output is correct
17 Correct 5 ms 480 KB Output is correct
18 Correct 4 ms 348 KB Output is correct
19 Correct 10 ms 11100 KB Output is correct
20 Correct 4 ms 604 KB Output is correct