답안 #914703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914703 2024-01-22T14:56:01 Z racsosabe Lozinke (COCI17_lozinke) C++14
100 / 100
12 ms 9564 KB
#include<bits/stdc++.h>
using namespace::std;

const int N = 20000 + 5;
const int L = 12;
const int SUML = 20000 * 10 + 5;
const int E = 26;

int n;
int len[N];
char s[N][L];
int nodes = 1;
int frec[SUML];
bool vis[SUML];
int trie[E][SUML];

void insert(int id) {
	int pos = 0;
	for(int i = 0; i < len[id]; i++) {
		int c = s[id][i] - 'a';
		if(trie[c][pos] == 0) trie[c][pos] = nodes++;
		pos = trie[c][pos];
	}
	frec[pos] += 1;
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%s", s[i]);
		len[i] = strlen(s[i]);
		insert(i);
	}
	long long res = 0;
	for(int id = 1; id <= n; id++) {
		for(int i = 0; i < len[id]; i++) {
			int pos = 0;
			for(int j = i; j < len[id]; j++) {
				int c = s[id][j] - 'a';
				if(trie[c][pos] == 0) break;
				pos = trie[c][pos];
				if(not vis[pos]) {
					res += frec[pos];
					vis[pos] = true;
				}
			}
		}
		for(int i = 0; i < len[id]; i++) {
			int pos = 0;
			for(int j = i; j < len[id]; j++) {
				int c = s[id][j] - 'a';
				if(trie[c][pos] == 0) break;
				pos = trie[c][pos];
				vis[pos] = false;
			}
		}
		res -= 1;
	}
	printf("%lld\n", res);
	return 0;
}

Compilation message

lozinke.cpp: In function 'int main()':
lozinke.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
lozinke.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   scanf("%s", s[i]);
      |   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2496 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 3 ms 2908 KB Output is correct
10 Correct 5 ms 4604 KB Output is correct
11 Correct 4 ms 3144 KB Output is correct
12 Correct 10 ms 7516 KB Output is correct
13 Correct 7 ms 3040 KB Output is correct
14 Correct 9 ms 9308 KB Output is correct
15 Correct 12 ms 9564 KB Output is correct
16 Correct 7 ms 2908 KB Output is correct
17 Correct 6 ms 2892 KB Output is correct
18 Correct 5 ms 2956 KB Output is correct
19 Correct 7 ms 4588 KB Output is correct
20 Correct 6 ms 2908 KB Output is correct