QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84867 | #5666. Repetitive Elements | u2x1# | AC ✓ | 5ms | 3432kb | C++14 | 938b | 2023-03-06 20:26:46 | 2023-03-06 20:26:47 |
Judging History
answer
#include <iostream>
#include <map>
#include <string>
#define orep(i,l,r) for(auto i = (l); i < (r); ++i)
#define NL std::cout << '\n';
const int maxN = 2e5+5;
int arr[maxN];
std::string s;
bool check(const int x, std::string &ret) {
std::map<std::string, int> cnt;
for(auto i = 0ul; i+x <= s.size(); i++) {
++cnt[s.substr(i, x)];
}
auto j = 0ul;
for(auto i = 0ul; i+x <= s.size(); i++) {
while(j < i+x) { cnt[s.substr(j, x)]--; j++; }
if (cnt[s.substr(i, x)]) { ret = s.substr(i,x); return 1; }
}
return 0;
}
int main() {
std::ios::sync_with_stdio(0); std::cin.tie(0);
int t; std::cin >> t;
while(t--) {
std::cin >> s;
std::string ret;
int l = 1, r = s.size();
while(l < r-1) {
const int mid = (l+r) >> 1;
if (check(mid, ret)) { l = mid; }
else { r = mid; }
}
std::cout << ret; NL;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3432kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 5ms
memory: 3408kb
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