QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#680546 | #5666. Repetitive Elements | Kdlyh# | AC ✓ | 3ms | 3780kb | C++20 | 1.1kb | 2024-10-26 21:28:57 | 2024-10-26 21:28:57 |
Judging History
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