QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#183965 | #5666. Repetitive Elements | MahmoudAtia# | AC ✓ | 11ms | 9324kb | C++14 | 1.2kb | 2023-09-20 04:55:36 | 2023-09-20 04:55:36 |
Judging History
answer
#include <bits/stdc++.h>
typedef long double ld;
typedef long long ll;
using namespace std;
int di[] = {1, 0, -1, 0, 0, 1, -1, 1};
int dj[] = {0, 1, 0, -1, -1, 0, 1, -1};
const ll oo = 1e18;
const int N = 5e5 + 5, M = 1e4 + 5, MOD = 1e9 + 7;
#define EPS 1e-9
ll n, t, m, k, pw[N], h[N], p = 31;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//memset(dp, -1, sizeof dp);
pw[0] = 1;
for (int i = 1; i < N; i++) pw[i] = (pw[i - 1] * p) % MOD;
cin >> t;
while (t--) {
string s;
cin >> s;
n = s.length();
for (int i = 1; i <= n; i++) h[i] = (h[i - 1] + pw[i] * (s[i - 1] - 'A')) % MOD;
string ans;
for (int i = n; i >= 1; i--) {
map<int, int> mp;
int idx = 1e9;
for (int j = i; j <= n; j++) {
ll hash = (h[j] - h[j - i] + MOD) % MOD * pw[n - j] % MOD;
if (mp[hash]) {
if (j - mp[hash] >= i) idx = min(idx, mp[hash]);
} else mp[hash] = j;
}
if (idx != 1e9) {
cout << s.substr(idx - i, i) << "\n";
break;
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8504kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 11ms
memory: 9324kb
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