제출 #165741

#제출 시각아이디문제언어결과실행 시간메모리
165741SenseiLozinke (COCI17_lozinke)C++17
85 / 100
1081 ms33144 KiB
#include <bits/stdc++.h>

using namespace std;

const long long P = 61;
const long long MOD = 1e16 + 3;

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;
}

// vector<char> st[MAXN + 7];
string st[MAXN + 7];
long long fullhash[MAXN + 7];
// vector<long long> subhashes[MAXN + 7];
unordered_set<long long> subhashes[MAXN + 7];
char buff[12];
multiset<long long> fullhashes;

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

	for (int i = 1; i <= N; i++) {
		// scanf("%s", buff);

		// for (int j = 0; buff[j] != 0; j++) {
		// 	st[i].push_back(buff[j]);
		// }

		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);
		}

		fullhash[i] = hash;
		fullhashes.insert(hash);
	}

	long long ans = 0;

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

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

				// subhashes[i].push_back(hash);

				if (subhashes[i].find(hash) == subhashes[i].end()) {
					subhashes[i].insert(hash);
					ans += fullhashes.count(hash);
				}
			}
		}

		// sort(subhashes[i].begin(), subhashes[i].end());
	}

	ans -= N;

	// for (int i = 1; i <= N; i++) {
	// 	for (long long hash : subhashes[i]) {
	// 		ans += fullhashes.count(hash);
	// 	}

	// 	ans--;
	// }

	cout << ans << "\n";

	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

lozinke.cpp: In function 'int main()':
lozinke.cpp:43:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < st[i].size(); j++) {
                   ~~^~~~~~~~~~~~~~
lozinke.cpp:55:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int ss = 0; ss < st[i].size(); ss++) {
                    ~~~^~~~~~~~~~~~~~
lozinke.cpp:58:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = ss; j < st[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...