import java.io.*;
import java.util.*;
public class lozinke {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String[] vals = new String[n];
for(int i = 0; i < n; i++) vals[i] = br.readLine();
Arrays.sort(vals, (a, b) -> a.length() - b.length());
HashMap<String, Integer> occ = new HashMap<String, Integer>();
int ans = 0;
for(int i = 0; i < n; i++) {
HashSet<String> used = new HashSet<String>();
for(int j = 0; j < vals[i].length(); j++) {
for(int k = j; k < vals[i].length(); k++) {
String sub = vals[i].substring(j, k+1);
if(occ.containsKey(vals[i].substring(j, k+1)) && !used.contains(vals[i].substring(j, k+1))) {
used.add(vals[i].substring(j, k+1));
ans += occ.get(vals[i].substring(j, k+1));
if(j == 0 && k == vals[i].length() - 1) ans++;
// occ.put(vals[i].substring(j, k+1), occ.get(vals[i].substring(j, k+1)) + 1);
}
else {
;
}
}
}
if(occ.containsKey(vals[i])) {
occ.put(vals[i], occ.get(vals[i]) + 1);
}
else {
occ.put(vals[i], 1);
}
}
PrintWriter pw = new PrintWriter(System.out);
pw.println(ans);
pw.close();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
9156 KB |
Output is correct |
2 |
Incorrect |
79 ms |
8948 KB |
Output isn't correct |
3 |
Incorrect |
97 ms |
9224 KB |
Output isn't correct |
4 |
Incorrect |
117 ms |
9992 KB |
Output isn't correct |
5 |
Incorrect |
213 ms |
16872 KB |
Output isn't correct |
6 |
Incorrect |
232 ms |
14656 KB |
Output isn't correct |
7 |
Incorrect |
243 ms |
17248 KB |
Output isn't correct |
8 |
Incorrect |
227 ms |
14784 KB |
Output isn't correct |
9 |
Incorrect |
475 ms |
19068 KB |
Output isn't correct |
10 |
Incorrect |
377 ms |
15552 KB |
Output isn't correct |
11 |
Incorrect |
520 ms |
19676 KB |
Output isn't correct |
12 |
Incorrect |
456 ms |
17536 KB |
Output isn't correct |
13 |
Incorrect |
491 ms |
17220 KB |
Output isn't correct |
14 |
Incorrect |
813 ms |
18244 KB |
Output isn't correct |
15 |
Incorrect |
509 ms |
17436 KB |
Output isn't correct |
16 |
Incorrect |
538 ms |
18024 KB |
Output isn't correct |
17 |
Incorrect |
311 ms |
15820 KB |
Output isn't correct |
18 |
Incorrect |
453 ms |
16276 KB |
Output isn't correct |
19 |
Incorrect |
648 ms |
17184 KB |
Output isn't correct |
20 |
Incorrect |
694 ms |
21340 KB |
Output isn't correct |