QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#269945 | #5666. Repetitive Elements | STnofarjo# | AC ✓ | 2ms | 3616kb | C++20 | 1.1kb | 2023-11-30 11:59:46 | 2023-11-30 11:59:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 128, mod = 1e9+7;
long long t, n, presum[maxn], pow4[maxn];
string s;
bool sama(long long a, long long b, long long len){
long long kiri = (presum[a+len] + mod - presum[a]) % mod;
long long kanan = (presum[b+len] + mod - presum[b]) % mod;
return (kiri * pow4[b-a] % mod == kanan);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
pow4[0] = 1;
for(int i=1; i<maxn; i++){
pow4[i] = pow4[i-1] * 5 % mod;
}
cin >> t;
while(t--){
cin >> s; n = s.length();
// itung presum
presum[0] = 0;
for(int i=0; i<n; i++){
presum[i+1] = presum[i];
if(s[i] == 'T'){
presum[i+1] += pow4[i];
}else if(s[i] == 'C'){
presum[i+1] += pow4[i] * 2;
}else if(s[i] == 'G'){
presum[i+1] += pow4[i] * 3;
}
}
bool udah = false;
for(int i=n/2; i>0 && !udah; i--){
for(int j=0; j+2*i<=n && !udah; j++){
for(int k=j+i; k+i<=n && !udah; k++){
if(sama(j, k, i)){
for(int m=0; m<i; m++){
cout << s[j+m];
} cout << endl;
udah = true;
}
}
}
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 3616kb
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