Submission #867383

# Submission time Handle Problem Language Result Execution time Memory
867383 2023-10-28T10:00:23 Z Vladth11 Lozinke (COCI17_lozinke) C++14
95 / 100
61 ms 65536 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 = 200002;
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 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 3164 KB Output is correct
9 Correct 3 ms 2904 KB Output is correct
10 Correct 7 ms 10332 KB Output is correct
11 Correct 5 ms 5464 KB Output is correct
12 Runtime error 61 ms 65536 KB Execution killed with signal 9
13 Correct 7 ms 2904 KB Output is correct
14 Correct 13 ms 20504 KB Output is correct
15 Correct 17 ms 22620 KB Output is correct
16 Correct 6 ms 604 KB Output is correct
17 Correct 5 ms 348 KB Output is correct
18 Correct 4 ms 348 KB Output is correct
19 Correct 12 ms 11356 KB Output is correct
20 Correct 4 ms 604 KB Output is correct