# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
229547 | Uzumaki_Naturoo | Rima (COCI17_rima) | C++14 | 1060 ms | 127352 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/// You just can't beat the person who never gives up
/// ICPC next year
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std ;
const int N = 5e5+5 ,M = 3e6+5 ;
typedef unsigned long long ull ;
const int base = 29 ;
int mod[4] = {(int)1e9+9 ,(int)1e9+7 ,(int)1e9-63 ,(int)1e9-71};
struct rabinKarp{
int val[4] ;
rabinKarp(){
memset(val,0,sizeof val);
}
void push_back(int x){
for(int i=0;i<4;++i){
val[i] = (1ll * val[i] * base) %mod[i];
val[i] = (val[i] + x) %mod[i];
}
}
pair<ull ,ull> hashVal(){
ull a = val[0] ,b = val[2] ;
a *= 1e10 ,b *= 1e10 ;
a += val[1] ,b += val[3] ;
return {a ,b} ;
}
};
int n ;
char str[M] ;
vector<pair<ull,ull>> h[N] ;
map<pair<ull,ull> ,int> cnt ;
set<pair<ull,ull>> all ;
int main(){
scanf("%d",&n);
for(int i=0;i<n;++i){
scanf("%s",str);
int m = strlen(str);
reverse(str,str+m) ;
rabinKarp rbk ;
h[i].push_back(make_pair(0,0));
for(int j=0;j<m;++j){
rbk.push_back(str[j]-'a'+1);
h[i].push_back(rbk.hashVal());
}
++cnt[h[i][h[i].size()-2]] ;
all.insert(h[i].back());
}
int ans = 0 ;
for(int i=0;i<n;++i){
int cur = 0 ;
while(h[i].size()>=2 && all.count(h[i].back())){
cur += cnt[h[i][h[i].size()-2]] ;
h[i].pop_back();
}
ans = max(ans ,cur);
}
printf("%d",ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |