# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
585941 | MilosMilutinovic | Lozinke (COCI17_lozinke) | C++14 | 270 ms | 13504 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
using namespace std;
#ifdef LOCAL
#define eprintf(...) {fprintf(stderr, __VA_ARGS__);fflush(stderr);}
#else
#define eprintf(...) 42
#endif
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
const int B1 = 453571;
const int MOD1 = 1e9 + 9;
const int B2 = 744313;
const int MOD2 = 1e9 + 7;
const int N = 20020;
string s[N];
int n;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
startTime = clock();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin >> n;
for (int i = 0; i < n; i++)
cin >> s[i];
sort(s, s + n, [&](string a, string b) {
if (a.size() != b.size())
return a.size() < b.size();
return a < b;
});
map<pii, int> cnt;
ll ans = 0;
for (int i = 0; i < n; i++) {
int m = (int)s[i].size();
ll myHash1 = 0;
ll myHash2 = 0;
set<pair<ll, ll>> st;
for (int l = 0; l < m; l++) {
ll hsh1 = 0, hsh2 = 0;
for (int r = l; r < m; r++) {
hsh1 = hsh1 * B1 + (s[i][r] - 'a' + 1);
hsh1 %= MOD1;
hsh2 = hsh2 * B2 + (s[i][r] - 'a' + 1);
hsh2 %= MOD2;
st.insert(mp(hsh1, hsh2));
}
if (l == 0)
myHash1 = hsh1, myHash2 = hsh2;
}
for (auto p : st)
ans += cnt[p];
cnt[mp(myHash1, myHash2)]++;
}
for (auto& p : cnt) {
ans += (ll)p.second * (p.second - 1) / 2;
}
printf("%lld", ans);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |