QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#736399#5666. Repetitive ElementsSanguineChameleon#AC ✓2ms3592kbC++201.3kb2024-11-12 10:46:352024-11-12 10:46:35

Judging History

你现在查看的是最新测评结果

  • [2024-11-12 10:46:35]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3592kb
  • [2024-11-12 10:46:35]
  • 提交

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();
    }
}

Details

Tip: Click on the bar to expand more detailed information

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