답안 #165735

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
165735 2019-11-28T12:18:23 Z Sensei Lozinke (COCI17_lozinke) C++17
40 / 100
1000 ms 12536 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;
}

vector<char> st[MAXN + 7];
long long fullhash[MAXN + 7];
vector<long long> subhashes[MAXN + 7];
char buff[12];

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

	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 (ss == 0 && j + 1 == st[i].size()) {
					fullhash[i] = hash;
				}
			}
		}

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

	long long ans = 0;

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (i != j && binary_search(subhashes[i].begin(), subhashes[i].end(), fullhash[j]) == true) {
				ans++;
			}
		}
	}

	cout << ans << "\n";

	return 0;
}

Compilation message

lozinke.cpp: In function 'int main()':
lozinke.cpp:36:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int ss = 0; ss < st[i].size(); ss++) {
                    ~~~^~~~~~~~~~~~~~
lozinke.cpp:39:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = ss; j < st[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~
lozinke.cpp:44:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (ss == 0 && j + 1 == st[i].size()) {
                    ~~~~~~^~~~~~~~~~~~~~~
lozinke.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", buff);
   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1272 KB Output is correct
2 Correct 3 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 8 ms 1400 KB Output is correct
5 Correct 27 ms 1528 KB Output is correct
6 Correct 54 ms 1784 KB Output is correct
7 Correct 91 ms 1912 KB Output is correct
8 Correct 93 ms 2124 KB Output is correct
9 Execution timed out 1053 ms 4216 KB Time limit exceeded
10 Execution timed out 1070 ms 5596 KB Time limit exceeded
11 Execution timed out 1073 ms 5624 KB Time limit exceeded
12 Execution timed out 1068 ms 8568 KB Time limit exceeded
13 Execution timed out 1063 ms 10360 KB Time limit exceeded
14 Execution timed out 1079 ms 7032 KB Time limit exceeded
15 Execution timed out 1069 ms 9720 KB Time limit exceeded
16 Execution timed out 1083 ms 12536 KB Time limit exceeded
17 Execution timed out 1078 ms 12412 KB Time limit exceeded
18 Execution timed out 1067 ms 10360 KB Time limit exceeded
19 Execution timed out 1076 ms 8184 KB Time limit exceeded
20 Execution timed out 1087 ms 8184 KB Time limit exceeded