Submission #250210

# Submission time Handle Problem Language Result Execution time Memory
250210 2020-07-17T08:08:03 Z Vladikus004 Lozinke (COCI17_lozinke) C++14
75 / 100
469 ms 10488 KB
#include <bits/stdc++.h>
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;

const int N = 20000 + 3, P = 10;
int n;
string s[N];
ull h[11],deg[11];

void make_hash(string &s){
    h[0] = s[0] - 'a' + 1;
    deg[0] = 1;
    for (int i = 1; i < s.size(); i++){
        h[i] = h[i - 1] * P + (s[i] - 'a' + 1);
        deg[i] = deg[i - 1] * P;
    }
}

ull get_hash(int l, int r){
    if (!l) return h[r];
    return h[r] - h[l - 1] * deg[r - l + 1];
}

map <ull, int> mp;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif // LOCAL
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> s[i];
    }
    sort(s, s + n);
    reverse(s, s + n);
    int ans = 0;
    for (int i = 0; i < n; i++){
        make_hash(s[i]);
        set <ull> ms;
        for (int j = 0; j < s[i].size(); j++){
            for (int k = j; k < s[i].size(); k++){
                ms.insert(get_hash(j, k));
            }
        }
        ans += mp[get_hash(0, s[i].size() - 1)];
        for (auto u: ms){
            mp[u]++;
        }
    }
    mp.clear();
    reverse(s, s + n);
    for (int i = 0; i < n; i++){
        make_hash(s[i]);
        set <ull> ms;
        for (int j = 0; j < s[i].size(); j++){
            for (int k = j; k < s[i].size(); k++){
                ms.insert(get_hash(j, k));
            }
        }
        ans += mp[get_hash(0, s[i].size() - 1)];
        for (auto u: ms){
            mp[u]++;
        }
    }
    cout << ans;
}

Compilation message

lozinke.cpp: In function 'void make_hash(std::__cxx11::string&)':
lozinke.cpp:18:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < s.size(); i++){
                     ~~^~~~~~~~~~
lozinke.cpp: In function 'int main()':
lozinke.cpp:48:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < s[i].size(); j++){
                         ~~^~~~~~~~~~~~~
lozinke.cpp:49:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int k = j; k < s[i].size(); k++){
                             ~~^~~~~~~~~~~~~
lozinke.cpp:63:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < s[i].size(); j++){
                         ~~^~~~~~~~~~~~~
lozinke.cpp:64:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int k = j; k < s[i].size(); k++){
                             ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 2 ms 1024 KB Output is correct
5 Correct 9 ms 1280 KB Output is correct
6 Correct 14 ms 1280 KB Output is correct
7 Correct 22 ms 1792 KB Output is correct
8 Incorrect 34 ms 2176 KB Output isn't correct
9 Correct 74 ms 2424 KB Output is correct
10 Incorrect 181 ms 5496 KB Output isn't correct
11 Correct 129 ms 3832 KB Output is correct
12 Incorrect 450 ms 10488 KB Output isn't correct
13 Correct 187 ms 2552 KB Output is correct
14 Incorrect 304 ms 9080 KB Output isn't correct
15 Incorrect 469 ms 10104 KB Output isn't correct
16 Correct 149 ms 1280 KB Output is correct
17 Correct 54 ms 1152 KB Output is correct
18 Correct 40 ms 1152 KB Output is correct
19 Correct 274 ms 7216 KB Output is correct
20 Correct 83 ms 1272 KB Output is correct