QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#680546#5666. Repetitive ElementsKdlyh#AC ✓3ms3780kbC++201.1kb2024-10-26 21:28:572024-10-26 21:28:57

Judging History

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

  • [2024-10-26 21:28:57]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3780kb
  • [2024-10-26 21:28:57]
  • 提交

answer

#include<bits/stdc++.h>

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(...) 42
#endif

using i64 = long long;
#define int long long

namespace ranges = std::ranges;

void solve()
{
#define tests
    std::string s; std::cin >> s; int n{std::ssize(s)};

    auto check = [&](int len) {
        for (int i = 0; i + len - 1 < n; i++) {
            for (int j = i + len; j + len - 1 < n; j++) {
                if (s.substr(i, len) == s.substr(j, len)) {return true;}
            }
        }
        return false;
    };

    int lo{}, hi{n}; while (lo <= hi) {int mid{hi + lo >> 1}; check(mid) ? lo = mid + 1 : hi = mid - 1;}
    int len{lo - 1};
    for (int i = 0; i + len - 1 < n; i++) {
        for (int j = i + len; j + len - 1 < n; j++) {
            if (s.substr(i, len) == s.substr(j, len)) {std::cout << s.substr(i, len) << "\n"; return ;}
        }
    }

}

signed main()
{
   std::cin.tie(nullptr)->sync_with_stdio(false);
   int _(1);
#ifdef tests
   std::cin >> _;
#endif
   while(_--) solve();
   return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3780kb

input:

5
TATCGATCGAGTTGT
TCCGCGAGCGAGTCTCTCCATT
GTTTCATCATACGAGGCCCCATACGCGCTGG
AGATGGGATCCTTATG
GCCCTTAGGCATGGGATGTCGTTTCTTG

output:

ATCG
GCGA
CATACG
GAT
CTT

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 3552kb

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