Submission #97756

# Submission time Handle Problem Language Result Execution time Memory
97756 2019-02-18T10:21:56 Z dalgerok Lozinke (COCI17_lozinke) C++17
95 / 100
1000 ms 15544 KB
#include<bits/stdc++.h>
using namespace std;


struct super_hash{
    size_t operator()(string x)const{
        unsigned long long cur = 0, p = 1;
        for(auto it : x){
            cur += p * it;
            p *= 59;
        }
        return cur;
    }
};

unordered_map < string, int, super_hash > q;

inline void add(string &s){
    unordered_map < string, int, super_hash > used;
    for(int i = 0; i < (int)s.size(); i++){
        string t;
        for(int j = i; j < (int)s.size(); j++){
            t += s[j];
            if(used.find(t) == used.end()){
                q[t] += 1;
                used[t] = true;
            }
        }
    }
}
inline void del(string &s){
    unordered_map < string, int, super_hash > used;
    for(int i = 0; i < (int)s.size(); i++){
        string t;
        for(int j = i; j < (int)s.size(); j++){
            t += s[j];
            if(used.find(t) == used.end()){
                q[t] -= 1;
                used[t] = false;
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    string s[n];
    for(int i = 0; i < n; i++){
        cin >> s[i];
        add(s[i]);
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        del(s[i]);
        ans += q[s[i]];
        add(s[i]);
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 21 ms 768 KB Output is correct
6 Correct 40 ms 892 KB Output is correct
7 Correct 43 ms 1536 KB Output is correct
8 Correct 68 ms 2176 KB Output is correct
9 Correct 267 ms 2324 KB Output is correct
10 Correct 473 ms 7172 KB Output is correct
11 Correct 352 ms 4072 KB Output is correct
12 Execution timed out 1031 ms 15544 KB Time limit exceeded
13 Correct 592 ms 2680 KB Output is correct
14 Correct 663 ms 14264 KB Output is correct
15 Correct 985 ms 15400 KB Output is correct
16 Correct 594 ms 1152 KB Output is correct
17 Correct 266 ms 1144 KB Output is correct
18 Correct 188 ms 1144 KB Output is correct
19 Correct 633 ms 8164 KB Output is correct
20 Correct 314 ms 1280 KB Output is correct