QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#214551 | #5666. Repetitive Elements | AnthonyQwO# | AC ✓ | 24ms | 3784kb | C++14 | 1.6kb | 2023-10-14 21:02:30 | 2023-10-14 21:02:30 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MXN=1000;
//double hash
const int P1=12421;
const int P2=75577;
const int MOD=1e9+7;
pair<int,int> Hash[MXN];
void build(const string& s){
pair<int,int> val = make_pair(0,0);
Hash[0]=val;
for(int i=1; i<=s.size(); i++){
val.first = (val.first * P1 + s[i-1]) % MOD;
val.second = (val.second * P2 + s[i-1]) % MOD;
Hash[i] = val;
}
}
int qpow( int n, int k ) {
int res=1;
for( ; k ; n=n*n%MOD, k>>=1 ) if( k&1 ) res=res*n%MOD;
return res;
}
bool cmp( int i, int j, int len ) {
return ((Hash[i+len-1].first-Hash[i-1].first*qpow(P1,len)%MOD+MOD)%MOD == (Hash[j+len-1].first-Hash[j-1].first*qpow(P1,len)%MOD+MOD)%MOD)
&& ((Hash[i+len-1].second-Hash[i-1].second*qpow(P2,len)%MOD+MOD)%MOD == (Hash[j+len-1].second-Hash[j-1].second*qpow(P2,len)%MOD+MOD)%MOD);
}
int print( int i, int len ) {
return (Hash[i+len-1].first-Hash[i-1].first*qpow(P1,len)%MOD+MOD)%MOD;
}
signed main()
{
// H[r] - H[l-1] * p^(r-l+1)
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int q;
cin>>q;
for(;q--;) {
string str, res;
cin>>str;
int n=str.size(), maxi=0;
build(str);
for( int k=1 ; k <= n ; k++ ) {
for( int i=1 ; i+k <= n ; i++ ) {
for( int j=i+k ; j+k-1 <= n ; j++ ) {
if( cmp(i,j,k) && k > maxi )
maxi=k, res=str.substr(i-1,k);
}
}
}
cout<<res<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3784kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 24ms
memory: 3560kb
input:
50 TTGACAACTTCAGGTTGGCACTCCTTCATTTGGATTTCGGAATAATAGTTTTCTGCTCTGCC ATCCTATTCGGGGATAGGAGAGATGGGTTGCCGCTATAAAAGCATTTGAACTCCATTTCACTCCGTTGGCTAGGGGTCGCACTG CCGTAATATAAAGACTCGGAATTCCAATAGCTGCTATTTGCGAGTATGTGACTGAAAACACACCTATAAATATTAGCTGCGTACAAGCTA ATGGCTGCATGCAGGGTCGACTAGACACACTTTGTCT TTGAGGATGTCGACGTGTCT...
output:
CTTCA CATTT TAGCTGC TGCA ACGTG GCGCCGG CTCTT AGTAT AGAG ACAG TAT TGAC CTTG CGTC TACTGG GCCGGT GAA CAGTA GCGT GGTT CCCT GAG TAGAC GGTGC GCAGT TGAG ATCAA CCACACA GAGTC ATGTA ATGGTA TATA TATGAA TTCC CATACG TACCA TTAG GGAATGT CAGG GCT AAG CTGT GGAT TCTTC AAAAC ATG GATAA TTA ACATAT CAAT
result:
ok 50 lines