Submission #107987

#TimeUsernameProblemLanguageResultExecution timeMemory
107987FrankenweenLozinke (COCI17_lozinke)C++17
100 / 100
469 ms13432 KiB
#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 mod1 = (ll)1e9 + 7; const ll mod2 = (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<pair<ll, ll>, ll> cnt; vector<string> arr(n); cin >> arr; for (int i = 0; i < n; i++) { ll h1 = 0, h2 = 0; for (auto c : arr[i]) { h1 = (h1 * BASE + c - 'a' + 1) % mod1; h2 = (h2 * BASE + c - 'a' + 1) % mod2; } cnt[{h1, h2}]++; } ll answer = 0; for (auto &s : arr) { set<pair<ll, ll>> d; for (int i = 0; i < s.size(); i++) { ll h1 = 0, h2 = 0; for (int j = i; j < s.size(); j++) { h1 = (h1 * BASE + s[j] - 'a' + 1) % mod1; h2 = (h2 * BASE + s[j] - 'a' + 1) % mod2; d.insert({h1, h2}); } } 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 (stderr)

lozinke.cpp: In function 'void solve()':
lozinke.cpp:53:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < s.size(); i++) {
                         ~~^~~~~~~~~~
lozinke.cpp:55:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = i; j < s.size(); j++) {
                             ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...