QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#87651 | #5666. Repetitive Elements | CCSU_Wine | AC ✓ | 1ms | 3712kb | C++14 | 1.6kb | 2023-03-13 23:02:06 | 2023-03-13 23:02:10 |
Judging History
answer
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
#define ull unsigned long long
const int N = 110, MAX = 100, mod = 1000000933;
char a[N];
ull p1[N], h1[N];
ll p2[N], h2[N], n;
void init(){
p1[0] = p2[0] = 1;
for(int i = 1; i <= MAX; i ++){
p1[i] = p1[i - 1] * 13331;
// p2[i] = p2[i - 1] * 131 % mod;
}
}
void Hash(){
for(int i = 1; i <= n; i ++){
h1[i] = h1[i - 1] * 13331 + a[i];
// h2[i] = (1ll * h2[i - 1] * 131 % mod + a[i]) % mod;
}
}
ull get_hash1(int l, int r){
return h1[r] - h1[l - 1] * p1[r - l + 1];
}
ll get_hash2(int l, int r){
return (h2[r] - h2[l - 1] * p2[r - l + 1] % mod + mod) % mod;
}
void solve(){
scanf("%s",a + 1);
n = strlen(a + 1);
Hash();
int resl, resr;
for(int i = 1; i <= n; i ++){//枚举长度
for(int j = 1; j + i - 1 <= n; j ++){//枚举第一个开始的位置
int cnt = 1;
ull hash_val = get_hash1(j, j + i - 1);
for(int k = j + i; k + i - 1 <= n; k ++){
if(get_hash1(k, k + i - 1) == hash_val){
cnt ++;
break;
}
}
if(cnt == 2){
resl = j, resr = j + i - 1;
break;
}
}
}
for(int i = resl; i <= resr; i ++){
printf("%c",a[i]);
}
puts("");
}
int main(){
init();
int t;
scanf("%d",&t);
while(t --) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3712kb
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