QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#87650 | #5666. Repetitive Elements | CCSU_Wine | WA | 2ms | 3576kb | C++14 | 1.6kb | 2023-03-13 23:00:33 | 2023-03-13 23:00:36 |
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, 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: 0
Wrong Answer
time: 2ms
memory: 3576kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
AT TC TC GA GC
result:
wrong answer 1st lines differ - expected: 'ATCG', found: 'AT'