QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#184275 | #5666. Repetitive Elements | ucup-team1508# | AC ✓ | 5ms | 3884kb | C++14 | 1.7kb | 2023-09-20 16:06:08 | 2023-09-20 16:06:09 |
Judging History
answer
#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)
#define Fd(i, a, b) for(int i = a; i >= b; i --)
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
// map<string, char> mp;
const int mod1 = 998244353;
const int mod2 = 1e7 + 49;
const int base1 = 250316;
const int base2 = 171925;
struct hash {
int n; string s;
vector<pii> ha, pw;
void init(string t) {
s = t, n = s.size();
ha.resize(n + 1), pw.resize(n + 1);
pw[0] = {1, 1};
F(i, 1, n) {
pw[i].fi = 1ll * pw[i - 1].fi * base1 % mod1;
pw[i].se = 1ll * pw[i - 1].se * base2 % mod2;
}
F(i, 1, n) {
ha[i].fi = (1ll * ha[i - 1].fi * base1 + s[i - 1]) % mod1;
ha[i].se = (1ll * ha[i - 1].se * base2 + s[i - 1]) % mod2;
}
}
pii hsh(int l, int r) {
int x = (ha[r].fi - (1ll * ha[l - 1].fi * pw[r - l + 1].fi) % mod1 + mod1) % mod1;
int y = (ha[r].se - (1ll * ha[l - 1].se * pw[r - l + 1].se) % mod2 + mod2) % mod2;
return {x, y};
}
} a;
string s;
int n;
void sol() {
cin >> s;
n = s.size();
a.init(s);
Fd(k, n / 2, 1) {
F(i, 1, n) {
F(j, i + k, n) {
if(j + k - 1 > n || i + k - 1 > n) continue;
if(a.hsh(i, i + k - 1) == a.hsh(j, j + k - 1)) {
// cout << k << "\n";
F(z, i, i + k - 1) cout << s[z - 1];
cout << "\n";
return;
}
}
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t; cin >> t;
while(t --) sol();
}
Details
Tip: Click on the bar to expand more detailed information
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: 5ms
memory: 3884kb
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