#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long, long long>;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define eb emplace_back
#define vi vector<ll>
#define vb vector<bool>
#define f0(i,a) for(ll i=0;i<(a);i++)
#define f1(i,a) for(ll i=1;i<(a);i++)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define f first
#define s second
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
template<class Fun> class y_combinator_result {
Fun fun_;
public:
template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }
#ifdef I_AM_NOOB
#define gg(...) [](const auto&...x){ char c='='; cerr<<#__VA_ARGS__; ((cerr<<exchange(c,',')<<x),...); cerr<<endl; }(__VA_ARGS__);
#else
#define gg(...) 777771449
#endif
ll LOG2(ll x){ return __builtin_clzll(1ll) - __builtin_clzll(x); }
bool isPow2(ll n) {
return n && ((n & (n-1)) == 0);
}
ll LOG2C(ll x) {
if (isPow2(x)) return LOG2(x);
return LOG2(x)+1;
}
template <typename Iter, typename Cont>
bool is_last(Iter iter, const Cont& cont) {
return (iter != cont.end()) && (next(iter) == cont.end());
}
constexpr ll INFF = 1e18;
constexpr ll P = 1e9+7;
// constexpr ll P = 998244353;
int main() {
cin.tie(0) -> ios::sync_with_stdio(0);
map<string, ll> mp;
ll n; while (cin >> n) {
ll ans = 0;
vector<string> a(n);
f0(i, n) {
cin >> a[i];
string s = a[i];
set<string> st;
f0(j, s.size()) {
for (ll k = j; k < s.size(); k++) {
string t = s.substr(j, k-j+1);
st.insert(t);
}
}
for (auto t : st) mp[t]++;
}
// gg(mp);
f0(i, n) {
string s = a[i];
ans += mp[s]-1;
}
cout << ans << endl;
}
return 0;
}
Compilation message
lozinke.cpp: In function 'int main()':
lozinke.cpp:14:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | #define f0(i,a) for(ll i=0;i<(a);i++)
| ^
lozinke.cpp:63:13: note: in expansion of macro 'f0'
63 | f0(j, s.size()) {
| ^~
lozinke.cpp:64:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for (ll k = j; k < s.size(); k++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
860 KB |
Output is correct |
6 |
Correct |
10 ms |
860 KB |
Output is correct |
7 |
Correct |
14 ms |
1372 KB |
Output is correct |
8 |
Correct |
23 ms |
2376 KB |
Output is correct |
9 |
Correct |
57 ms |
2488 KB |
Output is correct |
10 |
Correct |
116 ms |
7508 KB |
Output is correct |
11 |
Correct |
95 ms |
4376 KB |
Output is correct |
12 |
Correct |
302 ms |
16752 KB |
Output is correct |
13 |
Correct |
172 ms |
2956 KB |
Output is correct |
14 |
Correct |
213 ms |
15048 KB |
Output is correct |
15 |
Correct |
312 ms |
16468 KB |
Output is correct |
16 |
Correct |
173 ms |
1432 KB |
Output is correct |
17 |
Correct |
52 ms |
1112 KB |
Output is correct |
18 |
Correct |
35 ms |
1116 KB |
Output is correct |
19 |
Correct |
178 ms |
8792 KB |
Output is correct |
20 |
Correct |
92 ms |
1364 KB |
Output is correct |