# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
94338 |
2019-01-17T18:36:25 Z |
zeyad49 |
Savez (COCI15_savez) |
Java 11 |
|
127 ms |
9944 KB |
import java.io.*;
import java.util.*;
class Savez{
static int n;
static int MOD=(int)1e9+9,p=31,pow[],maxN=(int)2e6+5;;
public static void main(String[] args) throws IOException {
Scanner sc=new Scanner();
PrintWriter out=new PrintWriter(System.out);
pow=new int [maxN];
pow[0]=1;
for(int i=1;i<maxN;i++) {
long x=pow[i-1]*1l*p%MOD;
pow[i]=(int)x;
}
n=sc.nextInt();
int ans=1;
HashMap<Integer,Integer> map=new HashMap();
for(int i=0;i<n;i++) {
char []s=sc.next().toCharArray();
int len=s.length;
int []hash=new int [len];
long last=0;
for(int j=0;j<len;j++) {
last=last+(s[j]-'A'+1)*1l*pow[j];
last%=MOD;
hash[j]=(int)last;
}
int dp=1;
for(int prefix=1;prefix<=len;prefix++) {
int preHash=hash[prefix-1],sufHash=hash[len-1]-(prefix==len?0:hash[len-1-prefix]);
if(sufHash<0)
sufHash+=MOD;
if(sufHash==(preHash*1l*pow[len-prefix]%MOD))
dp=Math.max(dp, 1+map.getOrDefault(preHash, 0));
}
map.put(hash[len-1], dp);
ans=Math.max(ans, dp);
}
out.println(ans);
out.close();
}
static class Scanner
{
BufferedReader br;
StringTokenizer st;
Scanner(){
br=new BufferedReader(new InputStreamReader(System.in));
}
Scanner(String fileName) throws FileNotFoundException{
br=new BufferedReader(new FileReader(fileName));
}
String next() throws IOException {
while(st==null || !st.hasMoreTokens())
st=new StringTokenizer(br.readLine());
return st.nextToken();
}
String nextLine() throws IOException {
return br.readLine();
}
int nextInt() throws IOException{
return Integer.parseInt(next());
}
long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(next());
}
double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(next());
}
}
}
Compilation message
Note: savez.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
81 ms |
9872 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
77 ms |
9592 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
81 ms |
9768 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
71 ms |
9612 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
74 ms |
9848 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
127 ms |
9944 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
72 ms |
9656 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
70 ms |
9784 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
79 ms |
9528 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
78 ms |
9668 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |