QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#323048#5666. Repetitive ElementsRabeya#AC ✓17ms3728kbC++202.1kb2024-02-08 11:42:092024-02-08 11:42:09

Judging History

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

  • [2024-02-08 11:42:09]
  • 评测
  • 测评结果:AC
  • 用时:17ms
  • 内存:3728kb
  • [2024-02-08 11:42:09]
  • 提交

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





詳細信息

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