QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#84867#5666. Repetitive Elementsu2x1#AC ✓5ms3432kbC++14938b2023-03-06 20:26:462023-03-06 20:26:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 20:26:47]
  • 评测
  • 测评结果:AC
  • 用时:5ms
  • 内存:3432kb
  • [2023-03-06 20:26:46]
  • 提交

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;
}

详细

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