QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#127748 | #5666. Repetitive Elements | dkdk | AC ✓ | 4ms | 3448kb | C++20 | 1.2kb | 2023-07-19 23:43:21 | 2023-07-19 23:43:24 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <cmath>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
int dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, -1, 1 };
const int N = 100010;
int len, ans;
string s;
bool check(int ln)
{
for (int i = 0; i <= (int)s.size() - 2 * ln; i++)
{
//printf("i == %d\n", i);
for (int j = i + ln; j <= s.size() - ln; j++)
{
if (s.substr(i, ln) == s.substr(j, ln))
{
//cout << s.substr(i, ln) << ' ' << s.substr(j, ln) << endl;
if (ln > len)len = ln, ans = i;
return true;
}
}
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--)
{
len = -1e9, ans = -1;
cin >> s;
int l = 1, r = (int)s.size() / 2;
while (l < r)
{
int mid = (l + r + 1) >> 1;
//cout << "mid " << mid << " l " << l << " r " << r << endl;
if (check(mid))l = mid;
else r = mid - 1;
}
//cout << "l " << len << " ans " << ans << endl;
for (int i = ans; i < ans + len; i++)cout << s[i];
cout << endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3448kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 4ms
memory: 3444kb
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