Submission #823555

# Submission time Handle Problem Language Result Execution time Memory
823555 2023-08-12T18:10:47 Z VMaksimoski008 Lozinke (COCI17_lozinke) C++14
100 / 100
207 ms 17776 KB
#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int32_t main() {
    setIO();

    int n;
    cin >> n;
    unordered_map<string, int> occ, imp_occ;
    set<string> imp;

    for(int i=0; i<n; i++) {
        string str;
        cin >> str;
        set<string> s;
        imp.insert(str);
        imp_occ[str]++;

        for(int j=0; j<sz(str); j++) {
            string curr = "";
            for(int k=j; k<sz(str); k++) {
                curr += str[k];
                s.insert(curr);
            }
        }

        for(const string &x : s)
            occ[x]++;
    }

    ll ans = 0;
    for(auto &x : occ) {
        if(imp.count(x.first))
            ans += (x.second - 1) * imp_occ[x.first];
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 5 ms 684 KB Output is correct
6 Correct 8 ms 832 KB Output is correct
7 Correct 11 ms 1572 KB Output is correct
8 Correct 17 ms 2392 KB Output is correct
9 Correct 42 ms 2996 KB Output is correct
10 Correct 84 ms 8704 KB Output is correct
11 Correct 69 ms 5284 KB Output is correct
12 Correct 199 ms 17200 KB Output is correct
13 Correct 115 ms 4136 KB Output is correct
14 Correct 159 ms 17776 KB Output is correct
15 Correct 207 ms 17520 KB Output is correct
16 Correct 120 ms 780 KB Output is correct
17 Correct 43 ms 544 KB Output is correct
18 Correct 32 ms 468 KB Output is correct
19 Correct 124 ms 9740 KB Output is correct
20 Correct 63 ms 860 KB Output is correct