QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#183939#5666. Repetitive ElementsMaGnsi0#AC ✓8ms3616kbC++17891b2023-09-20 01:24:262023-09-20 01:24:26

Judging History

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

  • [2023-09-20 01:24:26]
  • 评测
  • 测评结果:AC
  • 用时:8ms
  • 内存:3616kb
  • [2023-09-20 01:24:26]
  • 提交

answer

/**
 *    author:  MaGnsi0
 *    created: 19.09.2023 20:18:33
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T;
    cin >> T;
    while (T--) {
        string s;
        cin >> s;
        int n = (int)s.size();
        string ans = "";
        for (int l = n / 2; l >= 1; --l) {
            map<string, vector<int>> mp;
            for (int i = 0; i + l - 1 < n; ++i) {
                mp[s.substr(i, l)].push_back(i);
            }
            int min_i = n;
            for (auto [t, a] : mp) {
                if ((int)a.size() < 2) { continue; }
                if (a[0] + l - 1 >= a.back()) { continue; }
                if (a[0] < min_i) { ans = t, min_i = a[0]; }
            }
            if (!ans.empty()) { break; }
        }
        cout << ans << "\n";
    }
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3616kb

input:

5
TATCGATCGAGTTGT
TCCGCGAGCGAGTCTCTCCATT
GTTTCATCATACGAGGCCCCATACGCGCTGG
AGATGGGATCCTTATG
GCCCTTAGGCATGGGATGTCGTTTCTTG

output:

ATCG
GCGA
CATACG
GAT
CTT

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 8ms
memory: 3580kb

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