| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 403244 | penguinhacker | Lozinke (COCI17_lozinke) | C++14 | 131 ms | 2652 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const unsigned long long SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);
const int M=1e9+7, B1=31, B2=53;
int n;
ll ans;
map<string, int> oc[11];
map<ar<int, 2>, int> mp;
void add(ar<int, 2>& a, char c) {
a[0]=((ll)B1*a[0]+c)%M;
a[1]=((ll)B2*a[1]+c)%M;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i=0; i<n; ++i) {
string s;
cin >> s;
++oc[s.size()][s];
}
for (int i=1; i<=10; ++i) {
for (auto& x : oc[i]) {
set<ar<int, 2>> st;
string s=x.first;
ll cnt=x.second;
ans+=(ll)cnt*(cnt-1);
for (int i=0; i<s.size(); ++i) {
ar<int, 2> hsh={};
for (int j=i; j<s.size(); ++j) {
add(hsh, s[j]);
st.insert(hsh);
}
}
for (const ar<int, 2>& j : st)
if (mp.count(j))
ans+=cnt*mp[j];
ar<int, 2> hsh={};
for (char c : s)
add(hsh, c);
mp[hsh]+=cnt;
}
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
