Submission #165719

# Submission time Handle Problem Language Result Execution time Memory
165719 2019-11-28T11:40:39 Z Sensei Lozinke (COCI17_lozinke) C++17
65 / 100
1000 ms 20584 KB
#include <bits/stdc++.h>

using namespace std;

const long long P = 53;
const long long MOD = 1e9 + 7;

const int MAXN = 2e4;

long long add (long long x, long long y) {
	return ((x % MOD) + (y % MOD)) % MOD;
}

long long mul (long long x, long long y) {
	return ((x % MOD) * (y % MOD)) % MOD;
}

map<long long, set<int> > m;
string st[MAXN + 7];

int main () {
	int N;
	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> st[i];
	}

	for (int i = 1; i <= N; i++) {
		long long hash = 0;

		for (int j = 0; j < st[i].size(); j++) {
			hash = mul(hash, P);
			hash = add(hash, st[i][j] - 'a' + 1);
		}

		m[hash].insert(i);
	}

	long long ans = 0;

	for (int i = 1; i <= N; i++) {
		set<int> s;

		for (int ss = 0; ss < st[i].size(); ss++) {
			long long hash = 0;

			for (int j = ss; j < st[i].size(); j++) {
				if (ss == 0 && j + 1 == st[i].size()) {
					break;
				}

				hash = mul(hash, P);
				hash = add(hash, st[i][j] - 'a' + 1);

				for (int id : m[hash]) {
					if (id != i) {
						s.insert(id);
					}
				}
			}
		}

		ans += s.size();
	}

	long long ans2 = 0;

	for (int i = 1; i <= N; i++) {
		long long hash = 0;

		for (int j = 0; j < st[i].size(); j++) {
			hash = mul(hash, P);
			hash = add(hash, st[i][j] - 'a' + 1);
		}

		ans2 += m[hash].size() - 1;
	}

	ans += ans2;

	cout << ans << "\n";

	return 0;
}

Compilation message

lozinke.cpp: In function 'int main()':
lozinke.cpp:32:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < st[i].size(); j++) {
                   ~~^~~~~~~~~~~~~~
lozinke.cpp:45:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int ss = 0; ss < st[i].size(); ss++) {
                    ~~~^~~~~~~~~~~~~~
lozinke.cpp:48:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = ss; j < st[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~
lozinke.cpp:49:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (ss == 0 && j + 1 == st[i].size()) {
                    ~~~~~~^~~~~~~~~~~~~~~
lozinke.cpp:72:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < st[i].size(); j++) {
                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 888 KB Output is correct
2 Correct 3 ms 888 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 5 ms 1016 KB Output is correct
5 Correct 26 ms 1400 KB Output is correct
6 Correct 11 ms 1400 KB Output is correct
7 Correct 61 ms 2380 KB Output is correct
8 Correct 22 ms 3292 KB Output is correct
9 Execution timed out 1068 ms 3088 KB Time limit exceeded
10 Correct 118 ms 9720 KB Output is correct
11 Execution timed out 1081 ms 3880 KB Time limit exceeded
12 Incorrect 310 ms 20584 KB Output isn't correct
13 Correct 165 ms 4344 KB Output is correct
14 Execution timed out 1076 ms 13724 KB Time limit exceeded
15 Incorrect 347 ms 20536 KB Output isn't correct
16 Correct 127 ms 2292 KB Output is correct
17 Correct 48 ms 2112 KB Output is correct
18 Execution timed out 1079 ms 2808 KB Time limit exceeded
19 Correct 222 ms 11128 KB Output is correct
20 Execution timed out 1079 ms 2564 KB Time limit exceeded