QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#87650#5666. Repetitive ElementsCCSU_WineWA 2ms3576kbC++141.6kb2023-03-13 23:00:332023-03-13 23:00:36

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-13 23:00:36]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3576kb
  • [2023-03-13 23:00:33]
  • 提交

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'