Submission #34856

# Submission time Handle Problem Language Result Execution time Memory
34856 2017-11-16T08:12:59 Z szawinis Lozinke (COCI17_lozinke) C++14
90 / 100
1000 ms 15656 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e4+1;
const ll MOD = 1e9+7;

int n, ans;
string s[N];
pair<ll, ll> h[N];
map<pair<ll, ll>, int> mp;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> s[i];
		h[i].first = h[i].second = s[i][0] - 'a' + 1;
		for(int j = 1; j < s[i].length(); j++) {
			h[i].first = (h[i].first * 31 + s[i][j] - 'a' + 1) % MOD;
			h[i].second = (h[i].second * 37 + s[i][j] - 'a' + 1) % MOD;
		}
	}
	for(int i = 0; i < n; i++) {
		set<pair<ll, ll> > ls;
		for(int x = 0; x < s[i].length(); x++) {
			pair<ll, ll> currh = {s[i][x]-'a' + 1, s[i][x]-'a' + 1};
			ls.insert(currh);
			for(int y = x+1; y < s[i].length(); y++) {
				currh.first = (currh.first * 31 + s[i][y] - 'a' + 1) % MOD;
				currh.second = (currh.second * 37 + s[i][y] - 'a' + 1) % MOD;
				ls.insert(currh);
			}
		}
		for(auto p: ls) ans += mp[p];
		++mp[h[i]];
	}
	mp.clear();
	for(int i = n-1; i >= 0; i--) {
		set<pair<ll, ll> > ls;
		for(int x = 0; x < s[i].length(); x++) {
			pair<ll, ll> currh = {s[i][x]-'a' + 1, s[i][x]-'a' + 1};
			ls.insert(currh);
			for(int y = x+1; y < s[i].length(); y++) {
				currh.first = (currh.first * 31 + s[i][y] - 'a' + 1) % MOD;
				currh.second = (currh.second * 37 + s[i][y] - 'a' + 1) % MOD;
				ls.insert(currh);
			}
		}
		for(auto p: ls) ans += mp[p];
		++mp[h[i]];
	}
	cout << ans;
}

Compilation message

lozinke.cpp: In function 'int main()':
lozinke.cpp:18:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 1; j < s[i].length(); j++) {
                    ^
lozinke.cpp:25:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int x = 0; x < s[i].length(); x++) {
                    ^
lozinke.cpp:28:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int y = x+1; y < s[i].length(); y++) {
                       ^
lozinke.cpp:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int x = 0; x < s[i].length(); x++) {
                    ^
lozinke.cpp:43:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int y = x+1; y < s[i].length(); y++) {
                       ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3116 KB Output is correct
2 Correct 0 ms 3116 KB Output is correct
3 Correct 0 ms 3116 KB Output is correct
4 Correct 0 ms 3116 KB Output is correct
5 Correct 9 ms 3380 KB Output is correct
6 Correct 13 ms 3380 KB Output is correct
7 Correct 29 ms 3908 KB Output is correct
8 Correct 56 ms 4568 KB Output is correct
9 Correct 106 ms 4568 KB Output is correct
10 Correct 349 ms 8528 KB Output is correct
11 Correct 209 ms 5888 KB Output is correct
12 Execution timed out 1000 ms 15656 KB Execution timed out
13 Correct 303 ms 4436 KB Output is correct
14 Correct 659 ms 14204 KB Output is correct
15 Execution timed out 1000 ms 15392 KB Execution timed out
16 Correct 266 ms 3248 KB Output is correct
17 Correct 59 ms 3116 KB Output is correct
18 Correct 43 ms 3116 KB Output is correct
19 Correct 566 ms 9188 KB Output is correct
20 Correct 129 ms 3248 KB Output is correct