# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1011937 | 0npata | Lozinke (COCI17_lozinke) | C++17 | 185 ms | 13316 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vec vector
const int MX = 1e9+7;
mt19937 rng(54);
int rng_next(int mx) {
return uniform_int_distribution<int32_t>(0, mx)(rng);
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vec<string> a(n);
for(int i = 0; i<n; i++) cin >> a[i];
vec<int> pos_hash(10);
vec<int> let_hash(26);
for(int i = 0; i<10; i++) {
pos_hash[i] = rng_next(MX);
}
for(int i = 0; i<26; i++) {
let_hash[i] = rng_next(MX);
}
map<int, int> cnt;
for(int i = 0; i<a.size(); i++) {
set<int> subs;
for(int j = 0; j < a[i].size(); j++) {
int hash = 0;
for(int k = j; k<a[i].size(); k++) {
int pos = k-j;
hash += pos_hash[pos] * let_hash[a[i][k]-'a'];
subs.insert(hash);
}
}
for(int subh : subs) {
cnt[subh] += 1;
}
}
int ans = 0;
for(int i = 0; i<n; i++) {
int hash = 0;
for(int j = 0; j<a[i].size(); j++) {
hash += pos_hash[j] * let_hash[a[i][j]-'a'];
}
ans += cnt[hash]-1;
}
cout << ans << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |