QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#87651#5666. Repetitive ElementsCCSU_WineAC ✓1ms3712kbC++141.6kb2023-03-13 23:02:062023-03-13 23:02:10

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:02:10]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3712kb
  • [2023-03-13 23:02:06]
  • 提交

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