QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#182837#5666. Repetitive ElementsbonginnAC ✓977ms21064kbC++141.4kb2023-09-18 16:43:252023-09-18 16:43:25

Judging History

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

  • [2023-09-18 16:43:25]
  • 评测
  • 测评结果:AC
  • 用时:977ms
  • 内存:21064kb
  • [2023-09-18 16:43:25]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define IOS cin.tie(0);ios_base::sync_with_stdio(false);
#define INF 1e15+9
using namespace std;
const int maxn = 2e5+5;
typedef pair<int,int> P;
void solve(){
    string s;
    cin >> s;
    map <string,bool> mp[s.size() + 5];
    string ans ;
    int mx = 0;
    int le = 0;
    for(int i=0;i<s.size();i++){
        string now = "";
        for(int j=i;j>=0;j--){
            now = s[j] + now;
            for(int k=j-1;k>=0;k--){
                if(mp[k][now]){
                    if(now.size() >= mx){
                        if(now.size() == mx){
                            if(k - now.size() + 1 < le){
                                mx = now.size();
                                ans = now;
                                le = k - now.size() + 1;
                            }
                        }
                        else{
                            mx = now.size();
                            ans = now;
                            le = k - now.size() + 1;
                        }
                        
                    }
                }
            }
            mp[i][now] = true;
        }
    }
    cout << ans << '\n';
}

signed main(){IOS
    int T;
    cin >> T;
    while(T--){
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 4148kb

input:

5
TATCGATCGAGTTGT
TCCGCGAGCGAGTCTCTCCATT
GTTTCATCATACGAGGCCCCATACGCGCTGG
AGATGGGATCCTTATG
GCCCTTAGGCATGGGATGTCGTTTCTTG

output:

ATCG
GCGA
CATACG
GAT
CTT

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 977ms
memory: 21064kb

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