Submission #107985

# Submission time Handle Problem Language Result Execution time Memory
107985 2019-04-26T12:51:35 Z Frankenween Lozinke (COCI17_lozinke) C++17
80 / 100
530 ms 13444 KB
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

#define ull unsigned long long
#define pll pair<ll, ll>
#define mp make_pair
#define ll long long
#define pb push_back
#define deb(x) cout << #x << " = " << x << endl
#define all(x) x.begin(), x.end()
#define ld long double
const ll mod = (ll)1e9 + 9;
const ll BASE = 47;
const ll inf = (ll)1e18;
const long double e = 2.718281828459;
const long double pi = 3.141592653;
const ld EPS = 1e-9;


using namespace std;


template <class T>
istream& operator>>(istream &in, vector<T> &arr) {
    for (T &cnt : arr) {
        in >> cnt;
    }
    return in;
};


void solve() {
    ll n;
    cin >> n;
    map<ll, ll> cnt;
    vector<string> arr(n);
    cin >> arr;
    for (int i = 0; i < n; i++) {
        ll h = 0;
        for (auto c : arr[i]) {
            h = (h * BASE + c - 'a' + 1) % mod;
        }
        cnt[h]++;
    }
    ll answer = 0;
    for (auto &s : arr) {
        set<ll> d;
        for (int i = 0; i < s.size(); i++) {
            ll h = 0;
            for (int j = i; j < s.size(); j++) {
                h = (h * BASE + s[j] - 'a' + 1) % mod;
                d.insert(h);
            }
        }
        for (auto i : d) {
            answer += cnt[i];
        }
        answer--;
    }
    cout << answer;
}


int main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#else
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cout.precision(30);
    ll seed = time(0);
    //cerr << "Seed: " << seed << "\n";
    srand(seed);
    solve();
    return 0;
}

Compilation message

lozinke.cpp: In function 'void solve()':
lozinke.cpp:50:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < s.size(); i++) {
                         ~~^~~~~~~~~~
lozinke.cpp:52:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = i; j < s.size(); j++) {
                             ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 9 ms 640 KB Output is correct
7 Correct 13 ms 1280 KB Output is correct
8 Correct 25 ms 1920 KB Output is correct
9 Correct 53 ms 2140 KB Output is correct
10 Incorrect 186 ms 6136 KB Output isn't correct
11 Correct 112 ms 3576 KB Output is correct
12 Incorrect 442 ms 13444 KB Output isn't correct
13 Correct 128 ms 2356 KB Output is correct
14 Incorrect 247 ms 12152 KB Output isn't correct
15 Incorrect 530 ms 13380 KB Output isn't correct
16 Correct 123 ms 1152 KB Output is correct
17 Correct 28 ms 896 KB Output is correct
18 Correct 26 ms 1024 KB Output is correct
19 Correct 231 ms 7032 KB Output is correct
20 Correct 65 ms 1152 KB Output is correct