QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#736399 | #5666. Repetitive Elements | SanguineChameleon# | AC ✓ | 2ms | 3592kb | C++20 | 1.3kb | 2024-11-12 10:46:35 | 2024-11-12 10:46:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define mp make_pair
#define eb emplace_back
#define pb push_back
typedef pair<int,int> pii;
int mod=1e15+7;
int base=31;
string s;
int idx;
bool check(int x){
int h=0,xx=1;
bool res=0;idx=1e9;
map<int,int> mp;
for(int i=0;i<x;i++){
h+=(s[i]-'A'+1);
h*=base;h%=mod;
xx*=base;xx%=mod;
}
mp[h]=x-1;
for(int i=x;i<s.length();i++){
h-=((s[i-x]-'A'+1ll)*xx)%mod;
h+=mod;
h+=(s[i]-'A'+1);
h*=base;h%=mod;
if(mp.find(h)==mp.end())mp[h]=i;
else{
if(i-mp[h]>=x){
idx=min(idx,mp[h]);
res=1;
}
}
}
return res;
}
void solve(){
cin>>s;
int lo,hi,mid;
lo=1;hi=s.length();
while(lo<hi){
mid=hi-(hi-lo)/2;
if(check(mid)){
lo=mid;
}else{
hi=mid-1;
}
}
check(lo);
for(int i=idx-lo+1;i<=idx;i++){
cout<<s[i];
}
cout<<'\n';
}
int32_t main() {
ios_base::sync_with_stdio(false);cin.tie(0);
int tc;
cin>>tc;
while(tc--){
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3488kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 3592kb
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