QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#323048 | #5666. Repetitive Elements | Rabeya# | AC ✓ | 17ms | 3728kb | C++20 | 2.1kb | 2024-02-08 11:42:09 | 2024-02-08 11:42:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef unordered_map<int,int> umap;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define popcount __builtin_popcount
#define case cout<<"Case "<<__testcase-testcase<<": ";
#define endl '\n'
#define inf 1e18
long long compute_hash(string const& s) {
const int p = 31;
const int m = 1e9 + 7;
long long hash_value = 0;
long long p_pow = 1;
for (char c : s) {
hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m;
p_pow = (p_pow * p) % m;
}
return hash_value;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int testcase=1;
cin>>testcase;
int __testcase=testcase;
while(testcase--)
{
string s;
cin>>s;
int n=s.size();
int Hash[n+1][n+1];
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
string t;
for(int k=i;k<=j;k++) t+=s[k];
Hash[i][j]=compute_hash(t);
}
}
int ans[n+5][n+5];
for(int i=0;i<=n;i++)
for(int j=0;j<=n;j++) ans[i][j]=0;
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
int len=j-i+1;
for(int k=j+1;k<n;k++)
{
if(k+len-1<n and Hash[k][k+len-1]==Hash[i][j]) ans[i][j]++,k=k+len-1;
}
}
}
int mx=0;
pair<int,int> idx;
for(int i=0;i<n;i++)
for(int j=i;j<n;j++){
if(ans[i][j]>0 and mx<j-i+1){
mx=j-i+1;
idx.fi=i;
idx.se=j;
}
}
string res;
//cout<<mx<<' '<<idx.fi<<' '<<idx.se<<endl;
for(int i=idx.fi;i<=idx.se;i++) res+=s[i];
cout<<res<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3532kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 17ms
memory: 3728kb
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