#include <bits/stdc++.h>
#define inc(a,b,c) for(int a(b);a<=(c);a++)
#define dec(a,b,c) for(int a(b);a>=(c);a--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 25005;
const int MOD = 100003;
const int INF = 0x3f3f3f3f;
struct Word{ char c[25]; int id; };
int N, k, ans;
int len[MAX_N], val[MAX_N];
Word s[MAX_N];
// compare by first the length of common prefix with the longest word and then lexicographically
bool comp(Word a, Word b){
return val[a.id] == val[b.id] ? lexicographical_compare(a.c + 1, a.c + len[a.id] + 1, b.c + 1, b.c + len[b.id] + 1) : val[a.id] < val[b.id];
}
int main(){
//freopen("type.in", "r", stdin);
//freopen("type.out", "w", stdout);
scanf("%d", &N);
inc(i, 1, N)
scanf("%s", s[i].c + 1), s[i].id = i;
inc(i, 1, N){
len[i] = strlen(s[i].c + 1);
if(len[i] > len[k])
k = i;
}
inc(i, 1, N)
inc(j, 1, len[i])
if(s[i].c[j] == s[k].c[j])
val[i]++;
else
break;
sort(s + 1, s + N + 1, comp);
inc(i, 1, N){
int temp = 0;
while(temp < min(len[s[i - 1].id], len[s[i].id]) && s[i - 1].c[temp + 1] == s[i].c[temp + 1])
temp++;
inc(j, 1, len[s[i - 1].id] - temp)
ans++;
inc(j, temp + 1, len[s[i].id])
ans++;
ans++;
}
printf("%d\n", ans);
return 0;
}
Compilation message
printer.cpp: In function 'int main()':
printer.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
26 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
printer.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
28 | scanf("%s", s[i].c + 1), s[i].id = i;
| ~~~~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
492 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
620 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
1004 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
1260 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |