QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#95688#5666. Repetitive ElementsSGColin#AC ✓21ms1760kbC++14775b2023-04-11 13:27:322023-04-11 13:27:35

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-11 13:27:35]
  • 评测
  • 测评结果:AC
  • 用时:21ms
  • 内存:1760kb
  • [2023-04-11 13:27:32]
  • 提交

answer

#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=100;

int te,n;char s[maxn+5];
int fai[maxn+5];

int main(){
	for (scanf("%d",&te);te;te--){
		scanf("%s",s+1);n=strlen(s+1);
		for (int len=n/2;len;len--)
			for (int l=1,r=len;r<=n;l++,r++){
				for (int i=l+1,j=0;i<=r;i++){
					while (j && s[l+j]!=s[i]) j=fai[j];
					j+=(s[l+j]==s[i]);fai[i-l+1]=j;
				}
				int lst=-n,cnt=0;bool fl=true;
				for (int i=1,j=0;i<=n;i++){
					while (j && s[l+j]!=s[i]) j=fai[j];
					j+=(s[l+j]==s[i]);
					if (j==len){
						if (i<lst+len) {fl=false;break;}
						lst=i;cnt++;j=fai[j];
					}
				}
				if (cnt>1 && fl){
					for (int i=l;i<=r;i++) putchar(s[i]);puts("");
					goto OK;
				}
			}
		OK:continue;
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 1760kb

input:

5
TATCGATCGAGTTGT
TCCGCGAGCGAGTCTCTCCATT
GTTTCATCATACGAGGCCCCATACGCGCTGG
AGATGGGATCCTTATG
GCCCTTAGGCATGGGATGTCGTTTCTTG

output:

ATCG
GCGA
CATACG
GAT
CTT

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 21ms
memory: 1620kb

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